title: RTSP Programming with Java. How to read single part frames?
body: <p>I am trying to implement RTSP Server with Java for fun.</p>
  
  <p>Since I do not have any pre-knowledge about RTSP. 
  I am starting with analysis already made source code.</p>
  
  <p>I found those code in internet.</p>
  
  <p>Link : </p>
  
  <p><a href="http://nsl.cs.sfu.ca/teaching/09/820/streaming/Client.html" rel="nofollow">http://nsl.cs.sfu.ca/teaching/09/820/streaming/Client.html</a>
  <a href="http://nsl.cs.sfu.ca/teaching/09/820/streaming/Server.html" rel="nofollow">http://nsl.cs.sfu.ca/teaching/09/820/streaming/Server.html</a>
  <a href="http://nsl.cs.sfu.ca/teaching/09/820/streaming/VideoStream.html" rel="nofollow">http://nsl.cs.sfu.ca/teaching/09/820/streaming/VideoStream.html</a>
  <a href="http://nsl.cs.sfu.ca/teaching/09/820/streaming/RTPpacket.html" rel="nofollow">http://nsl.cs.sfu.ca/teaching/09/820/streaming/RTPpacket.html</a></p>
  
  <p>For this posting, I got question about VideoStream.java.</p>
  
  <p>it has a method like below :</p>
  
  <pre><code> public int getnextframe(byte[] frame) throws Exception
    {
      int length = 0;
      String length_string;
      byte[] frame_length = new byte[5];
  
      //read current frame length
      fis.read(frame_length,0,5);
  
      //transform frame_length to integer
      length_string = new String(frame_length);
      length = Integer.parseInt(length_string);
  
      return(fis.read(frame,0,length));
    }
  </code></pre>
  
  <p>As you can see, it casts byte[] to String than Integer. However, in my experience, the String turns out a hexa String. So I changed like... below.</p>
  
  <p><code>Integer.parseInt(length_string.trim(), 16);</code></p>
  
  <p>It looks OK sometimes, but sometimes gets Number Format Exception.
  When I print <code>length_string</code> variables, it show in console like <code>iso2a, vc1mp, 41��� ...</code>.</p>
  
  <p>I can not know what I am missing here. Can you explain what is the purpose of codes here?</p>
  
  <pre><code>length_string = new String(frame_length);
  length = Integer.parseInt(length_string);
  </code></pre>
  
  <p>P.S</p>
  
  <p>Is there anyone knows full implementation of these code or other samples which does not uses extra third party libs, it could be much help for me. </p>