No connection could be made because the target machine actively refuses it

别等时光非礼了梦想. 提交于 2019-12-06 03:53:30

The code above is listening to request coming from the loopback address. This will effectively only listen to connection on that network, and that network only includes your machine.

Have you tried listening to the address bound to the network from which the connection should be coming? On a local network it should be something like 192.168.x.x or 10.x.x.x

I've run into this before. The trick is to bind to 0.0.0.0 rather than 127.0.0.1. When you bind to 127.0.0.1 the server will only accept connections from localhost. Binding to 0.0.0.0 it will accept all requests.

You also may want to nmap the host machine from the client and see what ports it sees as being open.

EDIT: If you hard code the IP address of the machine in it the listener will only listen on that network interface. If you use 0.0.0.0 the listener will listen on all available network interfaces. This includes interfaces between your computer and a USB attached hand held device, a second network card or a VPN link.

try netstat -al on your machine (the exact command line varies between Windows and unix) and see if the server is listening on the port

Why don't you use .NET remoting? It is better than doing a TCP/IP client server. You can pass messages between objects.

Have you tried running the client server on the same machine to make sure the connection is made first? Beyond that try using the router assigned or static IP of the machine running the server vs binding to loopback.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!