c# - Why IPAddress.Any needs to connect to remote host? -


I am creating a client server application in C # where the server is a remote host. I have a router and a firewall in my network.

My client side code is

  hostSocket = new TcpClient (); HostSocket.Connect (serverIp, serverPort);   

and my server side code

eqListner = new TcpListener (IP address, eqIp), eqPort);

In this scenario I am able to connect the client to the same PC by giving IP 127.0.0.1, but when I run the server on another PC in my network, I can not connect .

Then I changed my server side code by following:

  IPAddress ipAddress = Dns.GetHostEntry (Dns.GetHostName ()). Address list [0]; IPEndPoint ipLocalEndPoint = new IPEDpoint (IPADress, eCaport); TCPLStanerEkelistner = New TCPLSTener (IPLOCLandPoint);   

But still the result is the same. After this I changed my server side code again:

eqListner = new TcpListener (IPAddress.Any, eqPort);

And it works perfectly well. I have read msdn for IPAddress.Any and have found that this property set server is for listening to client activity on all network interfaces

My question is that the IP address Does anyone need to connect to a remote host?

P> In this scenario I connect the client to the same PC by giving the IP 127.0.0.1 But I can not connect when I ran the server on another PC in my network

127.0. 0.1 know the loopback that is always a local host when the service and the client are on the same machine, it can be convenient.

You are better off coding services to listen on all the interfaces, in this way the server should change the way of changing your address to be updated or restarted.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -