问题
如果一直在客户端/服务端发送消息,接收无问题
比如 一直在客户端发送1,2,3  服务器接受1,2,3如果客户端发一次,服务器发一次,客户端发一次,服务器发一次 这样的话会出现,发送2次才能成功
第一次接收的是上一次的记录比如服务器发送1,客户端接收1,
客户端发送2,服务器接收1,--交换的第一次是上次记录
客户端发送3,服务器接收3---从这里开始正常
客户端发送4,服务器接收4然后
服务器发送5,客户端接收4,--交换的第一次是上次记录
服务器发送6,客户端接收6---从这里开始正常下面就是发送和接收的代码服务端接收代码while (true)
            {
                data = new byte[1024];
                int length = client.Receive(data);//接收的数据长度
                if (length > 0)
                {
                    this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + "客户IP:" + clientip.Address + "\t" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + Encoding.UTF8.GetString(data, 0, data.Length-1)));
                }
            }客户端接收while (true)
            {
                data = new byte[1024];
                length = newclient.Receive(data);//接收的数据长度
                if (length > 0)
                {
                    this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + "服务器IP:" + clientip.Address + "\t" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
                    this.Invoke(new Action(() => this.txtShow.Text += System.Environment.NewLine + Encoding.UTF8.GetString(data, 0, data.Length - 1)));
                }
            }服务端发送data = Encoding.UTF8.GetBytes(this.txtMsg.Text.Trim());
            client.Send(data, data.Length, SocketFlags.None);//发送信息
客户端发送data = Encoding.UTF8.GetBytes(this.txtMsg.Text.Trim());
            newclient.Send(data, data.Length, SocketFlags.None);//发送信息