谁来帮我看看服务器端代码有没有错?
static void Main(string[] args){
int port = 6000;
string IP = "127.0.0.1";
IPAddress ip = IPAddress.Parse(IP);
IPEndPoint IPEnd = new IPEndPoint(ip, port);
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket类
socket.Bind(IPEnd);//绑定2000端口
socket.Listen(0);//开始监听
Console.WriteLine("Wait for connect");
while (true)
{
Socket client = socket.Accept();//为新建连接创建新的Socket。
Console.WriteLine("Get a connect");
try{
string str = "";
byte[] myBytes = new byte[1024];
int bytes;
bytes = client.Receive(myBytes, myBytes.Length, 0);//从客户端接受信息
str += Encoding.ASCII.GetString(myBytes, 0, bytes);
Console.WriteLine("Server Get Message:{0}", str);//把客户端传来的信息显示出来
}
catch (ArgumentNullException e)
{
Console.WriteLine("ArgumentNullException: {0}", e);
client.Close();
socket.Close();
break;
}
catch (SocketException e)
{
Console.WriteLine("SocketException: {0}", e);
client.Close();
socket.Close();
break;
}
}
Console.ReadLine();
}