我正在使用TcpClient和套接字進行P2P聊天應用程序。網絡選擇
我已經寫下面的代碼來接受TcpClient的:
IPAddress[] ip = Dns.GetHostAddresses(Dns.GetHostName());
IPAddress ip_local = Dns.GetHostAddresses(Dns.GetHostName())[0];
// IPAddress ip_local = IPAddress.Parse(ip_local);
TcpListener tcpl = new TcpListener(new IPEndPoint(ip_local, 9277));
while (true)
{
try
{
tcpl.Start();
TcpClient tcpClient = tcpl.AcceptTcpClient();
StateObject state = new StateObject();
state.workSocket = tcpClient.Client;
tcpClient.Client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(OnReceive), state);
}
catch (Exception ex)
{
}
}
的問題是,它選擇不同的網絡[我有1 LAN和2個VMWARE網絡]每一次。所以問題是如何強制它採用局域網的網絡地址,即特定的網絡?
用**語言標記問題**這是關於。 – deceze 2012-04-09 05:11:17