Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get any answer from RTSP server

I can connect to my Rtsp server using pre made software, but with the following piece of code I am unable to get an answer from the server. Even though the connection is successfull, the server does not answer me.

public class RtspClient {

private Socket server;
private InputStream is = null;
private OutputStream os = null;
private int seqid = 1;
private String request, resp;
private byte[] buffer = new byte[4096];
private int len = 0;


public RtspClient(String rIp, int rPort) {

    try {
        //INIT
        server = new Socket(rIp, rPort);
        is = server.getInputStream();
        os = server.getOutputStream();
        System.out.println("Connected to "+ rIp + ":" + rPort);

        //COMMUNICATION
        Boolean isTalking = true;
        while(isTalking == true) {

            //sending request
            String request = new String("OPTIONS * RTSP/1.0\r\nCSeq: 0\r\n");
            os.write(request.getBytes(), 0, request.length());
            System.out.println("Sent: "+ request);
            /////////////////

            //getting response
            len = is.read(buffer, 0, buffer.length);

            if(len > 0) {
                resp= new String(buffer, 0, len);
            }
            else {
                resp = "empty";
            }

            System.out.println("Received: "+ resp);
            //////////////////
        }
    } catch (UnknownHostException e ) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

}

Here's a screenshot of wireshark : http://imageplay.net/img/tya22277766/Untitled.png

The answer from the server should be:

RTSP/1.0 200 OK
Supported: play.basic, con.persistent
Cseq: 0
Server: Wowza Media Server x.x.x.x buildxxx
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS, ANNOUNCE, RECORD, GET_PARAMETER
Cache-Control: no-cache

Thanks!

like image 331
Ted Gueniche Avatar asked Jul 31 '12 20:07

Ted Gueniche


1 Answers

Alright, to make it short, the request should be :

OPTIONS * RTSP/1.0\r\nCSeq: 0\r\n\r\n

instead of

OPTIONS * RTSP/1.0\r\nCSeq: 0\r\n\

Simply add a new line at the end and the server will answer

like image 159
Ted Gueniche Avatar answered Sep 30 '22 04:09

Ted Gueniche