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 ネットワークがあるため] 毎回異なるネットワークを選択することです。問題は、LAN、つまり特定のネットワークのネットワーク アドレスを強制的に取得する方法です。