我已经在Objective C中使用以下套接字设置在我的Mac上编写了一个服务器应用程序 -
addr4.sin_len = sizeof(addr4);
addr4.sin_family = AF_INET;
addr4.sin_port = htons(6832);
addr4.sin_addr.s_addr = htonl(INADDR_ANY);
if (kCFSocketSuccess != CFSocketSetAddress(_ipv4socket, (__bridge CFDataRef) [NSData dataWithBytes:&addr4 length:sizeof(addr4)])) {
[self stop];
return NO;
}
其IP = ABC.DEF.64.188
和子网掩码= 255.255.255.0
我的客户端使用以下套接字设置进入C# -
IPHostEntry ipHostInfo = Dns.Resolve("ABC.DEF.64.188");
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);
// Create a TCP/IP socket.
client = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
Windows机器的IP地址= ABC.DEF.205.118
(找到使用什么是我的IP?)。我猜Windows机器是在NAT后面,具有以下设置 -
Wireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . : stonybrook.edu
Link-local IPv6 Address . . . . . : fe80::cd7d:846d:564a:3fa5%12
IPv4 Address. . . . . . . . . . . : 172.24.17.97
Subnet Mask . . . . . . . . . . . : 255.255.240.0
Default Gateway . . . . . . . . . : 172.24.16.1
我在客户端收到以下错误,服务器永远不会看到新的传入连接 -
System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 130.245.64.188:6832 at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
两台计算机上都禁用了防火墙。当两台机器都在同一个子网上时,它可以正常工作。
如何使此连接有效?