0

Hi, I am wondering if it is possible to "transfer" a Socket connection to another ServerSocket?

So, say I listen for a connection on ServerSocket with port 1111. A connection is established, I know want to use a ServerSocket with port 2222 to handle this connection. Is he possible without listening for a new connection on that port?

Edited by MisterRaver: n/a

3
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by MisterRaver
Featured Replies
  • So how many server computers are you talking about? If you want to hand the connection off to a different computer in a server farm, then sorry, I don't know how to do that. If it's two threads on the same machine then there's no advantage in changing ports. Read More

0

Can you explain What do you want to do when the ServerSocket's accept() method returns a Socket with a connection? Normally you would pass that Socket to a class and method to handle it. Why can't you do that?

0

Yes I will pass it to a class to handle it but first I would like the connection to switch to another serversocket meaning the first serversocket is now free to accept another request very fast if you undertsand it

0

My guess is that you cannot transfer an open connection from one IP/port to another while keeping it open.
Why do you want to do this? Maybe there's another way...

0

I would like the connection to switch to another

That is what I suggested as being the normal way to do it. When accept returns with a connection, the socket is "switched" to a class and method on its own thread to handle and the program loops back immediately to wait for another connection on that port by using accept.

Edited by NormR1: n/a

0

You can have one ServerSocket that sits waiting in a loop accepting connections and passing each one to a new Thread that handles ongoing communication with that client. There's no need to change to a new port to do that.. Ie you can have one ServerSocket and multiple Sockets on a single port.

0

Ah well, the reason I wanted this was for load-balance, so connection goes to first free ServerSocket. So if I have load of http request at one time it can transfer connection to a free server which will then handle request.

1

So how many server computers are you talking about? If you want to hand the connection off to a different computer in a server farm, then sorry, I don't know how to do that. If it's two threads on the same machine then there's no advantage in changing ports.

This question has already been answered. Start a new discussion instead.
Be sure to adhere to our posting rules.