日期:2014-05-17 浏览次数:20784 次
//初始化接受套接字:寻址方案,以字符流方式和Tcp通信
socketReceive = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//获取本机IP地址并设置接受信息的端口
ipReceive = new IPEndPoint(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0], 8001);
//将本机IP地址和接受端口绑定到接受套接字
socketReceive.Bind(ipReceive);
//监听端口,并设置监听缓存大小为1024byte
socketReceive.Listen(1024);
Socket chat = socketReceive.Accept();//这里的accept有什么用,为什么不能用socketReceive直接进行通信,listen不是阻塞的吗?