Hi. I'm trying to connect to another server application. I instantiated the object as:

IPHostEntry RemoteipHostInfo2 = Dns.Resolve
(CM.MAIN.CONFIG.GetConfig(192.563.1.2));
IPAddress RemoteipAddress2 = RemoteipHostInfo2.AddressList[0];
IPEndPoint RemoteEndPoint2 = new IPEndPoint(RemoteipAddress2,
Int32.Parse("45236"));

Socket handler = new Socket(
AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

/* Thsi instantiates a socket to make a connection to the server inputting the server's ip and port information. */

/* However, when i print out the IP and port of both the local and remote machine as: */

(((IPEndPoint)handler.LocalEndPoint).Address.ToString()) -> prints correct
((IPEndPoint)handler.LocalEndPoint).Port.ToString() -> prints wrong.
IPAddress.Parse(((IPEndPoint)handler.RemoteEndPoint).Address.ToString()) -> prints correct.

((IPEndPoint)handler.RemoteEndPoint).Port.ToString() -> prints correct.

In other words, i'm connecting to a server specifying the server;'s ip and port. But when I read the port number that I am sending on, I'm getting a different port number every time.

Is this the default way this works or am I diong something wrong?


Jennifer