服务端 // Set the TcpListener on port 13000. IPAddress localAddr = IPAddress.Parse("127.0.0.1"); // TcpListener server = new TcpListener(port); listener = new TcpListener(localAddr, 12345); // Start listening for client requests. listener.Start(); // Enter the listening loop. while(true) { Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests. // You could also user server.AcceptSocket() here. TcpClient client = listener.AcceptTcpClient(); Console.WriteLine("Connected!"); }
客户端 IPAddress hostAddress = new IPAddress(new byte[] { 192,168,1,230}); s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Connect(hostAddress,12345);192.168.1.230是服务段IP地址 运行到 s.Connect(hostAddress,12345) 时候出现"由于目标机器积极拒绝,无法连接."错误。着急!!!!!!!!!!!!!!!!!!!!!!!!!
haha, i have run into the same situation.pls try to run another service that your application is required.you can use FireDaemon Service Manager software to run services.
// Set the TcpListener on port 13000.
IPAddress localAddr = IPAddress.Parse("127.0.0.1"); // TcpListener server = new TcpListener(port);
listener = new TcpListener(localAddr, 12345); // Start listening for client requests.
listener.Start(); // Enter the listening loop.
while(true)
{
Console.Write("Waiting for a connection... "); // Perform a blocking call to accept requests.
// You could also user server.AcceptSocket() here.
TcpClient client = listener.AcceptTcpClient();
Console.WriteLine("Connected!");
}
IPAddress hostAddress = new IPAddress(new byte[] { 192,168,1,230}); s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.Connect(hostAddress,12345);192.168.1.230是服务段IP地址 运行到 s.Connect(hostAddress,12345) 时候出现"由于目标机器积极拒绝,无法连接."错误。着急!!!!!!!!!!!!!!!!!!!!!!!!!
我用web写的tcp传输
客户都收不到数据
但发送没出错
同样的代码在winform就没有任何问题 这是什么原因呢