Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
OPTIONS rtsp://localhost:8080 RTSP/1.0
CSeq: 2
User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)
And I want to send the following response back
RTSP/1.0 200 OK
CSeq: 2
Public: DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE
What should I use to construct the http response. Should I use HttpResponse or just use a plain byte array and convert it to ByteBuf?
The Netty version I'm using is 4.1.5
Thanks in advance.
The RTSP response of OPTIONS request contains only headers.
Then you can simply create the reponse and fill it using :
FullHttpResponse response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
response.headers().add(RtspHeadersNames.PUBLIC, "DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE");
response.headers().add(RtspHeadersNames.CSEQ, cseq);
A simplified implementation of an RTSP server answering to OPTIONS request could be :
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.*;
import io.netty.handler.codec.rtsp.*;
public class RtspServer {
public static class RtspServerHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelReadComplete(ChannelHandlerContext ctx) {
ctx.flush();
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof DefaultHttpRequest) {
DefaultHttpRequest req = (DefaultHttpRequest) msg;
FullHttpResponse response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
response.headers().add(RtspHeadersNames.PUBLIC, "DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE");
response.headers().add(RtspHeadersNames.CSEQ, req.headers().get("CSEQ"));
response.headers().set(RtspHeadersNames.CONNECTION, RtspHeadersValues.KEEP_ALIVE);
ctx.write(response);
public static void main(String[] args) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup);
b.channel(NioServerSocketChannel.class);
b.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
p.addLast(new RtspDecoder(), new RtspEncoder());
p.addLast(new RtspServerHandler());
Channel ch = b.bind(8554).sync().channel();
System.err.println("Connect to rtsp://127.0.0.1:8554");
ch.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.