Reputation:
I am trying to achieve a client server application in Java using UDP. The issue is when client connects to a server, server registers the client and another application tries to use the clientIP and clientPort to connect to the client; client is not able to get any data.
I was able to recreate DatagramSocket to connect to Client using his IP and port but when this done by different application, the communication is not achieved.
I would like to mention the port I am listening to client on server is different than the port which the server application is using.
How can we achieve this communication?
Please help me. Thank you.
Upvotes: 3
Views: 377
Reputation: 930
Your comment, "when client connects to a server.." made me wonder if you used connect() on client's DatagramSocket. If so, don't call connect() on the socket. UDP is a connection-less protocol and connect() is not required. By calling connect() on UDP socket, the socket can only send/receive data to/from the host specified with the connect().
If this is not the case, then only reason I can think of is that your client machine may have some firewall enabled, or there's a NAT/Firewall in between your client and the server or other hosts. Check with Wireshark whether your client is receiving any packets from the other app.
Hope this helps.
Upvotes: 1
Reputation: 8278
I maybe miss the point but I think that in order for your client to be able to accept the connection attempts by other application running on your server you need to implement some listening module in your client (server-like part that accept incoming connections). You can find some usefull examples here: http://www.java2s.com/Code/Java/Network-Protocol/UDP.htm
Upvotes: 0