Socket接了一次数据后,不能再接了,怎么回事?
服务端:
private void Form1_Load(object sender, EventArgs e)
{
thread = new Thread(new ThreadStart(get));
thread.Start();
}
private void get()
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(getip()), 10);
socket.Bind(ipe);
isStart = true;
byte[] buff = new byte[1024];
while (isStart)
{
socket.Listen(10);
Socket conSocket = socket.Accept();
conSocket.Receive(buff);
string s = Encoding.Default.GetString(buff);
updateui(s); //在textbox显示
Thread.Sleep(200);
}
}
客户端:
private void button1_Click(object sender, EventArgs e)
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipe=new IPEndPoint(IPAddress.Parse( "192.168.0.3 "),10);
socket.Connect(ipe);
if (socket.Connected)
{