views:

26

answers:

1

Hi guys,

I would like to have some advices because I've got conflict between clients sending RTSP messages to the server. First at all I apologize to you all for my English.

Well, what I'm doing is a java streaming video application.

  • clients set TCP connection with the server for exchanging RTSP messages

  • server sends over UDP, to the client requesting, frames in RTP packets using JPEG Payload Type because my video is in MotionJPEG format.

To be more specific:

  1. Server uses Threads to handle clients TCP connection on the same port
  2. Every client connected sent to the server the port wants to use for UDP transmission.

The problem is that the server receive and analize RTSP messages on tcp communication but when a client more connect to server, RTPS messages confuse orders and my server want to convert to integer where are just string, take session number from "unicast" written and so on...

This is what I do to handle different clients:

  ServerSocket socket = new ServerSocket(7777);
    while(true) {
        System.out.println("\nAspettando una connessione...");
        Socket incoming = socket.accept();
        Server server = new Server(incoming);
        Thread t = new Thread(server);
        t.start();
    }

My class Server implements Runnable to handle the timer to play, pause and stop the streaming.

Well it works providing video streaming to one client, but the server confuses RTSP on TCP requestes from clients that freeze. If I close those and open a third one it starts to work again because server understands what is receiving.


To be more specific the exceptions in server depend on the RTSP message clients are sending. For example

$Server (should receive Cseq) receives from (/192.168.0.4): Session: 12345678

$Server (should receive Cseq) from (/127.0.0.1): Cseq: 4

So exceptions could be:

Exception in thread "Thread-3" java.lang.NullPointerException
        at java.util.StringTokenizer.<init>(StringTokenizer.java:182)
        at java.util.StringTokenizer.<init>(StringTokenizer.java:219)
        at progetto2.Server.run(Server.java:91)
        at java.lang.Thread.run(Thread.java:619)

or

when is found Transport: RTP/UDP;unicast;client_port=8888\r\n something like (I apologize I've lost the exception in thread line)

    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:449)
    at java.lang.Integer.parseInt(Integer.java:499)
    at progetto2.Server.run(Server.java:108)
    at java.lang.Thread.run(Thread.java:619)

So I should I handle different clients, should I use different TCP ports? I'm sorry but I remember for multiclient chat I didn't have these problems. I hope to have explained my problem in the best way.

Thank you to everyone for helping and advicing me!

Kind regards!

+1  A: 

The situation you describe is impossible. TCP does not reorder messages nor merge messages from different clients. You have a bug in your code. Probably something is static that should be an instance variable in your Server class.

EJP
That's it! I declared BufferedReader, PrinterWriter, session and other variables as static, basically because before I wrote the streaming code just for one client communication. I didn't care too much to transform. I'm sorry. Thank you very much!Actually now it works, but almost at the end of streaming server stop to send UDP packets and client stops to receive, but no exception are throwed...any idea?Kind regards
soneangel
What exception are you expecting, from what method, under what condition?
EJP
I've fixed it...Maybe i'm just tired. I forgot to inicialize the sequenceNumber of header I send to RTPpacket constructor from server side. So it happened that when sequence number of current image increment and reach the video length of 500 frames it stops. And even If I setup again it doesn't verify condition to be less then video length. I would have another question about other format of video if you could answer. I'm using Mjpeg (26 payload type) If I use mpeg (32 payload) I expect server exception sending udp packets: java.lang.NumberFormatException: For input string: ")H��
soneangel
Well it's *not* a number, is it? Without seeing the code or the stacktrace it's impossible to comment further. I suggest you make that a separate question, and post it properly.
EJP
Thanx a lot I'll do in a while!
soneangel