L
Lokanath Chhatria
We have a socket server program and a socket client program.
The server, where the socket server program runs, has two network adapters
and hence two IP Addresses.
If the server program listens to an IP Address Endpoint which client can't
resolve, the client doesn't work.
The server program's code is like:
// Establish the local endpoint for the socket.
IPAddress hostaddress = IPAddress.Parse(socketInfo.SourceIP);
IPEndPoint localEndPoint = new IPEndPoint(hostaddress, socketInfo.SourcePort);
// Create a TCP/IP socket.
listenerSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
listenerSocket.Bind(localEndPoint);
i.e it listens to one of the IP Addresses.
To solve the problem, I changed
IPEndPoint localEndPoint = new IPEndPoint(hostaddress, socketInfo.SourcePort);
to
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any,
socketInfo.SourcePort);
As "IPAddress.Any" would listen to both the IP Addresses for the given port.
But this did not work.
Can anyone tell me how to make a socket server listen to all the IP Address
of the server
The server, where the socket server program runs, has two network adapters
and hence two IP Addresses.
If the server program listens to an IP Address Endpoint which client can't
resolve, the client doesn't work.
The server program's code is like:
// Establish the local endpoint for the socket.
IPAddress hostaddress = IPAddress.Parse(socketInfo.SourceIP);
IPEndPoint localEndPoint = new IPEndPoint(hostaddress, socketInfo.SourcePort);
// Create a TCP/IP socket.
listenerSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
listenerSocket.Bind(localEndPoint);
i.e it listens to one of the IP Addresses.
To solve the problem, I changed
IPEndPoint localEndPoint = new IPEndPoint(hostaddress, socketInfo.SourcePort);
to
IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any,
socketInfo.SourcePort);
As "IPAddress.Any" would listen to both the IP Addresses for the given port.
But this did not work.
Can anyone tell me how to make a socket server listen to all the IP Address
of the server