To develop RtspClient(just message transaction, not playing video), I thought that I will use Netty, and I have created the classes as follow,(rtsp is creating toooo much problem to me, I don't know, is this because lag of knowledge? any-how...),
TestRtspClient.java
public class TestRtspClient {
private final String host;
private final int port;
public TestRtspClient(String host, int port) {
this.host = host;
this.port = port;
}
public void start() throws Exception {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(group);
bootstrap.channel(NioSocketChannel.class);
bootstrap.handler(new TestRtspClientInitializer());
Channel channel = bootstrap.connect(host, port).sync().channel();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//DESCRIBE rtsp://192.168.1.26:8554/nature.ts RTSP/1.0\r\nCSeq: 3\r\n\r\n
while(true) {
channel.write(br.readLine() + "\r\n");
channel.flush();
}
} finally {
group.shutdownGracefully();
}
}
public static void main(String[] args) throws Exception {
new TestRtspClient("192.168.1.26", 8554).start();
}
}
and here is TestRtspClientInitializer.java
public class TestRtspClientInitializer extends ChannelInitializer<SocketChannel> {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipe = ch.pipeline();
// pipe.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
// pipe.addLast("decoder", new StringDecoder());
// pipe.addLast("encoder", new StringEncoder());
// pipe.addLast("encoder", new RtspRequestEncoder());
// pipe.addLast("decoder", new RtspResponseDecoder());
pipe.addLast("encoder", new HttpRequestEncoder());
pipe.addLast("decoder", new HttpResponseDecoder());
pipe.addLast("handler", new TestRtspClientHandler());
}
}
and here is TestRtspClientHandler.java
public class TestRtspClientHandler extends ChannelInboundMessageHandlerAdapter<HttpObject> {
@Override
public void messageReceived(ChannelHandlerContext ctx, String msg) throws Exception {
if(msg instanceof HttpResponse) {
System.out.println("Rtsp Response");
} else if(msg instanceof HttpRequest) {
System.out.println("Rtsp Request");
} else {
System.err.println("not supported format");
}
}
}
and I am using Live555MediaServer as RtspServer and Netty 4.0.0.CR3. When I am using DelimiterBasedFrameDecoder with stringdecoder and encoder its working fine, but If I use RtspRequest/Response encoder/decoder I am getting following warning, and no msg will be sent to L555.(also same with HttpReq/Resp encoder and decoder)
passing this as commandline arg in eclipse
DESCRIBE rtsp://192.168.1.26:8554/nature.ts RTSP/1.0\\r\\nCSeq: 3\\r\\n
Mar 25, 2014 6:45:28 PM io.netty.channel.DefaultChannelPipeline$ByteHeadHandler flush WARNING: Discarded 1 outbound message(s) that reached at the head of the pipeline. Please check your pipeline configuration.
Help me to fix this issue, and also explain me in-brief what is wrong in this code modules.
Thank You.
First of all, please upgrade to the latest Netty 4.0.x version.
Because you specified <String>
when you extend ChannelInboundMessageHandlerAdapter
in your TestRtspClientHandler
, it will only receive a message whose type is String
, which is not the case. You have to use HttpObject
instead of String
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.