5

我可以使用预制软件连接到我的 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

谢谢!

4

1 回答 1

5

好吧,简而言之,请求应该是:

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

代替

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

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

于 2012-08-02T17:34:35.410 回答