C/S通讯问题
private void button1_Click(object sender, EventArgs e){
IPEndPoint ip = new IPEndPoint(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0], 8001);
Socket sk = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sk.Bind(ip);
sk.Listen(1024);
Socket ac = sk.Accept();
byte[] by = new byte[1024];
int sum = ac.Receive(by);
IPEndPoint ip2 = (IPEndPoint)ac.RemoteEndPoint;
listBox1.Items.Add("来自" + ip2.Address + "对你说");
listBox1.Items.Add(Convert.ToSingle(sum));
ac.Close();
sk.Close();
}
这是服务端程序的代码,当我点击按钮时,程序死机啦,没办法我改了下端口,把8001成别的了,程序又说,通常每个套接字地址(协议/网络地址/端口)只允许使用一次。这到底是怎么回事啊,帮帮忙哈