I\'m very new to socket programming:
Is it possible to explicitly set the the source port on a Java Socket?
I am working on a client/server application in which
You can use this call to create socket,
public Socket(InetAddress address,
int port,
InetAddress localAddr,
int localPort)
throws IOException
This is normally done for UDP and this is not advised for TCP connections. If you do this for TCP on both ends, you can only have one TCP connection. If you create one more, the socket layer will get confused and you will end up lose all your connections.
For TCP, the common practice is to reply in the same connection. If you have to reply in a different connection, use a pre-defined ports on client also.