1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| try
{
m_socListener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//IPAddress[] ipdns = Dns.GetHostAddresses("localhost");
IPAddress ip = IPAddress.Parse("192.168.1.111");
//textBox1.Text = ipdns[0].ToString();
//IPHostEntry ipHostEntry = Dns.GetHostEntry(Dns.GetHostName());
//IPAddress ip = ipHostEntry.AddressList[0];
IPEndPoint ipLocal = new IPEndPoint(ip,8221);
m_socListener.Bind(ipLocal);
m_socListener.Listen(1);
m_socListener.BeginAccept(new AsyncCallback(OnClientConnect), null);
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
public void OnClientConnect(IAsyncResult asyn)
{
try
{
m_socWorker=m_socListener.EndAccept(asyn);
}
catch (ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
} |
Partager