sending data to a client that is behind proxy
I am implementing a chat application in Java using RMI and socket programming.
1. My client log in to the server using RMI
2. then Server open a ServerSocket on which it listens for data (messages) from client.
3. client sends message to the client
Till here everything is fine.
4. On log in client opens a ServerSocket so that it can receive messages from a server.
new ServerSocket(1235);
5. When server sends a message to a client on client's socket
new Socket(clientIP,1235)
now i get Exception (Connection Timed Out).
as i think it is because client is behind proxy and i am giving clientIP as 192.168.0.1 (for example).
now i have tried with proxy IP also
new Socket(proxyIP,1235)
again i get the same Exception (Connection timed out).
i think this is because the proxy server has no port 1235 open.
Can anyone help me to send data to the client from server.
I see what your doing wrong...I believe you are under the assumption that you need to open a socket back to your client.(Number 5. in your list). If so, that's wrong. You have already opened a socket and made a connection from your client to your server. Now all you need to do is communicate or execute your RMI methods over THAT connection.
I just don't have time to go any further, but I would recommend the link below to you. Get these examples in this link working on a SINGLE machine and then work on splitting them up between your client and server.
http://java.sun.com/docs/books/tutorial/rmi/overview.html
Hope this helps...
hi c2gill,
thanks for the response.
I think u are not getting my problem.
1. on the server when i get some message from a sender to a receiver i have to send the message to the sender (when the receiver is offline), but if the receiver is online how to send the message to receiver.
For that purpose i have to open a socket on the receiver but how to send data to that socket, as the receiver is behind the proxy.
> 1. My client log in to the server using RMI
Good.
> 2. then Server open a ServerSocket on which it
> listens for data (messages) from client.
Why? What's wrong with using another RMI call?
> 3. client sends message to the client
I assume you mean 'client sends message to the server'? Can you be more precise please?
> 4. On log in client opens a ServerSocket so that it
> can receive messages from a server.
If the client is behind a firewall it must have a proxy server or NAT port forwarder, configured appropriately, and specified to the server via a java.net.Proxy. Otherwise this will never work. How to configure a client-side proxy server is way beyond the scope of this forum. These forums are for questions about Java.
> on the server when i get some message from a sender to a receiver i have to send the message to the sender (when the receiver is offline),
I do not understand this sentence. You can't send a message to something that's offline.
If your server needs to send asynchronous messages to a client behind a firewall which needs to be configured, you have a seriously hard problem. You should review your requirements and talk them over with wherever they come from. I recommend you also see the Eight Fallacies of Distributed Computing: http://weblogs.java.net/jag/Fallacies.html.
If on the other hand the client is only going to receive synchronous data from the server in response to requests, forget all these ServerSockets and just use RMI more extensively.
ejpa at 2007-7-14 23:33:13 >

thanks.suppose i drop the concept of ServerSocket and use pure RMI, then how a client can send a file (file sharing) to another client (both clients are behind proxy).
I would recommend the following link for you and tell you to drop the RMI all together...The link below even has some examples that you could build up from. The examples contain both a client example AND a server example.
Socket and ServerSocket might be your answer....
http://java.sun.com/docs/books/tutorial/networking/sockets/index.html
Just remember this...The protocol between the two for a chat application would go "something" like this:
Start server.
Start client1 and connect/log into server.
Start client2 and connect/log into server.
Client2 fills out a message and sends to the server.
Server accepts and saves messages FROM client2.
On the same connection, server delivers any messages addressed TO client2.
and vice versa for client1.
Make your server the "middle" man for all transactions!
You could also keep track of the time on your client side application and after so many seconds or minutes, have the client automagically check the server for messages regardless of whether the client is sending a message or not...
Just a thought...<grin> Hope it helps....
Thanks,I have implemented whole project in RMI. can anyone suggest me how to transfer files between two client (both are behind proxy) directly without using server as a mediator.
This is a contradiction in in terms.One of the clients will have to become an RM server for the duration so the other client can contact it.And you will need htp://www.rmiproxy.com the RMI Proxy<plug/>.
ejpa at 2007-7-14 23:33:13 >

If i use one of the client a RMI server then i have to run RMIRegistry on that client.In a chat app (that is what i am building) is it feasible to run RMIRegistry on each client.
No you don't have to run an RMI Registry at the client. Just pass the callback object as a parameter to an RMI call on the server.
ejpa at 2007-7-14 23:33:13 >

Thanks,I will try this and ask again if any problems come.