日期:2014-05-17 浏览次数:20853 次
sockets = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress hostIP = IPAddress.Parse(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString());
IPEndPoint ep = new IPEndPoint(0, 7788);
sockets.Bind(ep);
sockets.Listen(10);
textBox1.BeginInvoke(new MethodInvoker(delegate
{
textBox1.Text += "侦听启动\r\n";
}));
while (thread.ThreadState != ThreadState.Aborted)
{
Socket sReceive = sockets.Accept();
textBox1.BeginInvoke(new MethodInvoker(delegate
{
textBox1.Text += ((IPEndPoint)sReceive.RemoteEndPoint).Address.ToString() + " 连接\r\n";
}));
int bufLen = sReceive.ReceiveBufferSize;
if (bufLen == 0) continue;
byte[] bData = new byte[bufLen];
int DataLen = sReceive.Receive(bData);
if (DataLen == 0) continue;
string StrData = Encoding.Default.GetString(bData, 0, DataLen);