Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Kean Keat Heng

+ Follow
since Aug 10, 2008
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kean Keat Heng

hi there,
Thanks for your insights.
I'm know sometimes I am too picky on details, a habit I got from my mentor.
Still trying to forward the request directly to the server.
Now reading on socket channels, doesn't seems like the solution though.

I abandoned the method before because it get too hard to managed the sockets connection. Still a newbie on sockets. I used thread to open the server socket on the client b4 the request has been sent out, sometimes it did open b4 the request, but sometimes it didn't. which is a problem to me since the server would hit a "connection refused" exception.
I have a server that is running and had multiple client connect directly to it by pointing to a specific IP and port number via socket.
The server socket as the listening side and the client uses normal socket.
The server is kinda like a application server that handles my home-brew RPC. Gives the server a message(string), the server runs it, return whatever result back to the client.

What leads to the problem
Now i am thinking of opening another server as a mean of load balancing. However, i do not want to change the coding in client that specifies the connection detail(ip, port)

So i decided to write a proxy server that stands in the previous server ip and port and will "forward/divert" the socket connection to the less busy server.

I had some leads of solution in mind:
Firstly, the message sent by the client have to be read by the proxy server to determine which server it should go to. This part i have no problem since the request wouldn't be as heavy

The Problem:
The major problem is if i send the request out using the proxy , the server will response to the proxy, and than the proxy will response to the client directly.
What i want to achieve here is that i wan the proxy to only divert the request and do not do any respond by itself. Which means that each server will get the request from proxy, but will send back the request directly to the client, not the proxy.

Tried (and abandoned) Method
I tried to another server socket at the client to listen and include the listening port and ip of the client and made the server to response to the server socket opened at the client, but it is inefficient and incurred too much overhead since 2 extra socket needs to be opened and threads in java doesn't guarantee the server socket in client will start listening when the server has done processing.