话不多说直接上代码:
string recvStr = ""; byte[] recvBytes = new byte[1024]; int bytes; do { bytes = clientSocket.Receive(recvBytes, recvBytes.Length, 0); //从客户端接受消息 recvStr += Encoding.ASCII.GetString(recvBytes, 0, bytes); } while (bytes == 1024); Console.WriteLine("{0} 收到:{1}", clientSocket.RemoteEndPoint.ToString(), recvStr);