UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » Java
  • » how to find Client's Destination Address from Server Side?

#1 2005-09-19 09:28 AM

SaravananS
Guest

Re: how to find Client's Destination Address from Server Side?

how to find Client's Destination Address from Server Side?

Assume that server machine has two IP Addresses 192.168.10.156 and 192.168.10.157 listening on Port number 3000

Suppose if any client communicates server on 3000 port with ipaddr 192.168.10.157

How should the server make sure that the client now contacts me in 192.168.10.157:3000 over UDP protocol(Datagram Programming)?

Is Any Method is there to find the client's destination IP address and Port number?

Please reply anyone who knows the solution,
Thanking you all,
Sarwan.

#2 2005-09-19 12:30 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,833
Website

Re: how to find Client's Destination Address from Server Side?

With TCP it's easy: just use getsockname() on the newly accept()'d socket...  But,
with UDP, it's more difficult...  The usual kluge method taken is to simply use
multiple sockets, one bound to each local IP, rather than a single socket bound
to INADDR_ANY...  That way, you can always tell which IP a client is coming in
through based on which socket the message comes from...  But, many systems
also have other methods you can use; usually sockopts like IP_PKTINFO,
IP_RCVDSTADDR, IP_RECVIF, etc...  It depends on what system you're on...

Offline

  • Index
  • » Java
  • » how to find Client's Destination Address from Server Side?

Board footer

Powered by FluxBB