mutiple sockets for one session
Hi everybody:
I'm trying to write a server that gets from the client data through 2 UDP and 2 TCP sockets. The problem starts when I need to granty that no other client will be connecting to these sockets. In other words, If a client request a connection how can I open and establish few more connections with the client. If I opened another ServerSocket then there's a possibility another client will connect to it. How can I make sure the connection request is coming only from the original client ?
Just hints or psedo code will do it.
thanx
[572 byte] By [
M-Aa] at [2007-10-2 23:11:24]

If there are no firewalls in the way you can have the client open a ServerSocket and tell you its port number over the existing connection. This is what FTP does.
Alternatively you could just have the client do multiple connects to the same ServerSocket and have something about joining an existing session in your application protocol.
ejpa at 2007-7-14 6:25:30 >

Something like this:
1st connection:
Client to server: Session 0 // i.e. give me a session number
Server to client: Session 12345 // i.e. the real session number
2nd connection from same client:
Client to server: Session 12345 // i.e. I want to rejoin session 12345
// Server checks that 12345 is from the same IP address and port
// if OK:
Server to client: Session 12345 // i.e. I agree that you can rejoin this session
// If not OK, server just closes the connection.
ejpa at 2007-7-14 6:25:30 >

I think that's the only possible way. The reason I didn't want to go for it is,because it adds alot of complixity to handle the connection if it is NOT for this session, as it has to be passed up muliple level to the parent thread to decide what to do with the request that did not meet any session number. As you know the server can not drop it immediately, it can be another client. Then the server have to check and decide. :)
Thanks alot any way. I do really appretiate your help.
M-Aa at 2007-7-14 6:25:30 >

I don't understand. There would be a single loop doing accepts, which would spawn a new Thread per accepted socket, which would do this protocol exchange, and then either join the socket to an existing session or start a new session.
You weren't planning to have another accept() somewhere were you? Don't. You will have to revisit the basic accept logic to implement this.
ejpa at 2007-7-14 6:25:30 >
