1

I ve got the following problem: I have a ServerSocket listening on Port x and want to redirect the connecting user to server a or server b (depends on server load).
When I just do it with one server ( by creating a new Socket for the target server and sending the server streams to the player), it all works like a charm
But when I try to change the Socket adress and port to redirect the player to another server, I get a Socket (close) Exception and the no user is being redirected.


Do you have any ideas/keywords for me to search for?
It is just important to redirect the player,connecting on port X to server a or server b ( or server c ...etc.) without interrupting the connection

Thanks in advance!
Max

0

3 Answers 3

1

I guess the default approach is to use a separate load-balancer in front of the two servers. Have you considered this option?

Best regards, Dido

Sign up to request clarification or add additional context in comments.

Comments

1

Once a Socket is open, the endpoints cannot be changed.

If you want transparent server selection, then some kind of network load-balancing is most appropriate.

If you can control the communication protocol, the client can request the initial server for a server:port pair for the data connection, and then reconnect to the new session. If the server indicates the current connection is acceptable, then just continue.

This way, each session will continue until the server proposes an alternative endpoint.

Comments

1

Option 1: Add the capability of specifying a redirect to your protocol. In other words, allow the server to reply on the socket with a message that indicates where the client should actually connect to. The first socket to the first server is closed and the client reacts to the redirect message by opening a second socket to the server that was indicated in the redirect message.

Option 2: Proxy the connection to the second server. In this case, the client keeps the initial connection to the first server. The first server opens a connection to a second server. The first server reads from the client and writes that data to the second connection. Likewise, it reads from the second connection and writes that data to the first connection.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.