java开发RtspClient
程序员文章站
2022-05-19 14:46:55
...
java开发RtspClient
socket chanel建立
if (selector == null) {
// 创建新的Selector
try {
selector = Selector.open();
} catch (final IOException e) {
e.printStackTrace();
}
}
try {
// 打开通道
socketChannel = SocketChannel.open();
// 绑定到本地端口
socketChannel.socket().setSoTimeout(30000);
socketChannel.configureBlocking(false);
socketChannel.socket().bind(localAddress);
if (socketChannel.connect(remoteAddress)) {
System.out.println("开始建立连接:" + remoteAddress);
}
socketChannel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ | SelectionKey.OP_WRITE,
this);
System.out.println("端口打开成功");
} catch (final IOException e1) {
e1.printStackTrace();
}
options 业务实现
private void doOption() {
StringBuilder sb = new StringBuilder();
sb.append("OPTIONS ");
sb.append(this.address.substring(0, address.lastIndexOf("/")));
sb.append(VERSION);
sb.append("\r\n");
sb.append("CSeq: ");
sb.append(seq++);
sb.append("\r\n");
sb.append("\r\n");
System.out.println(sb.toString());
send(sb.toString().getBytes());
}
交互报文
客户端发出的报文
服务端响应报文
Describe业务
代码实现
private void doDescribe() {
StringBuilder sb = new StringBuilder();
sb.append("DESCRIBE ");
sb.append(this.address);
sb.append(VERSION);
sb.append("\r\n");
sb.append("CSeq: ");
sb.append(seq++);
sb.append("\r\n");
sb.append("\r\n");
System.out.println(sb.toString());
send(sb.toString().getBytes());
}
客户端发出去的报文
服务响应报文
setup 业务
代码实现
private void doSetup() {
StringBuilder sb = new StringBuilder();
sb.append(“SETUP “);
sb.append(this.address);
sb.append(“/”);
sb.append(trackInfo);
sb.append(VERSION);
sb.append(“CSeq: “);
sb.append(seq++);
sb.append(“\r\n”);
sb.append(“Transport: RTP/AVP;UNICAST;client_port=16264-16265;mode=play”);
sb.append(“\r\n”);
sb.append(“\r\n”);
System.out.println(sb.toString());
send(sb.toString().getBytes());
}
客户端发出报文
服务端响应报文
play 业务
代码 实现
private void doPlay() {
StringBuilder sb = new StringBuilder();
sb.append("PLAY ");
sb.append(this.address);
sb.append(VERSION);
sb.append("Session: ");
sb.append(sessionid);
sb.append("CSeq: ");
sb.append(seq++);
sb.append("\r\n");
sb.append("\r\n");
System.out.println(sb.toString());
send(sb.toString().getBytes());
}
客户端发出报文
服务端接收报文
下一篇: AutoJsl布署(一)