Bri*_*ney 3 .net c# tcp tcplistener tcpclient
我正在使用C#编写一个简单的hello world TCP/IP客户端服务器应用程序,但无法让我的客户端连接.有人可以提供任何其他故障排除步骤 我开始没有想法......
以下是相关的代码部分:
服务器:
Console.Out.WriteLine("About to bind address");
IPAddress ipAd = IPAddress.Parse("127.0.0.1");
Console.Out.WriteLine("Choose a port to bind...");
String port = Console.In.ReadLine();
int iPort = Int32.Parse(port);
TcpListener myList = new TcpListener(ipAd, iPort);
myList.Start();
Console.WriteLine("The server is running at: "+myList.LocalEndpoint);
Console.WriteLine("Waiting for a connection.....");
Socket s = myList.AcceptSocket();
Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);
Run Code Online (Sandbox Code Playgroud)
客户:
Console.Out.WriteLine("enter address: ");
string address = Console.In.ReadLine();
Console.Out.WriteLine("enter port: ");
int port = Convert.ToInt32(Console.In.ReadLine());
TcpClient tcpclnt = new TcpClient();
Console.WriteLine("Connecting.....");
Console.Out.WriteLine("Address: " + address + ":" + port);
tcpclnt.Connect(address, port);
Run Code Online (Sandbox Code Playgroud)
我能够从客户端计算机ping服务器,但是我无法使用绑定端口telnet到服务器.我尝试了各种端口(少数端口在8000以下,少数在40000左右).我已在两个系统上禁用Windows防火墙.系统连接到不在互联网上的路由器.我尝试使用和不使用端口转发设置将给定端口上的传入请求转发到服务器计算机而不起作用.
我能够捕获的唯一例外是客户端抛出:
无法建立连接,因为目标计算机主动拒绝它.
我检查了一下,InnerException但似乎没有 - 这是基本的例外.这可能是对的吗?
不确定我还应该关注什么 - 任何其他故障排除步骤都会有所帮助.
谢谢!
上面的代码正在侦听来自环回地址的请求.这将有效地仅侦听该网络上的连接,并且该网络仅包括您的计算机.
您是否尝试过侦听绑定到网络的地址?在本地网络上,它应该是192.168.xx或10.xxx
| 归档时间: |
|
| 查看次数: |
14729 次 |
| 最近记录: |