关于Socket的问题,高手速度来啊。。
以下是我的程序:
int port = int.Parse(this.textBox2.Text);string host = this.textBox1.Text;IPAddress ip = IPAddress.Parse(host);IPEndPoint ipe = new IPEndPoint(ip, port);s = new Socke(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);//创建一个Socket类 s.Bind(ipe);//绑定8901端口 s.Listen(0);//开始监听 Socket temp = s.Accept();while (1 == 1){ string recvStr = ""; byte[] recvBytes = new byte[10240]; int bytes = 10240; bytes = temp.Receive(recvBytes, recvBytes.Length, 0);//从客户端接受信息 recvStr += Encoding.Unicode.GetString(recvBytes, 0, bytes); string a = UNcode.strtohex(recvStr.ToString()); if (a != "") { FileStream file = new FileStream("log.txt", FileMode.Append); StreamWriter sw = new StreamWriter(file); sw.Write(DateTime.Now.ToString() + " 日志记录信息:" + " " + a + "\n"); sw.Close(); file.Close(); } // DetailTPosition.DetailTPositions(a);}s.Close();