无法从RTSP服务器获得任何答案

时间:2012-07-31 20:04:53

标签: java sockets rtsp rtp

我可以使用预制软件连接到我的Rtsp服务器,但是使用以下代码我无法从服务器获得答案。即使连接成功,服务器也不回答我。

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();
    }
}

}

以下是wireshark的屏幕截图:http://imageplay.net/img/tya22277766/Untitled.png

服务器的答案应该是:

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

谢谢!

1 个答案:

答案 0 :(得分:4)

好吧,为了简短起见,请求应该是:

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

而不是

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

只需在末尾添加一个新行,服务器就会回答