//和客户端对话 private void dealClient() { Socket connection = this.connection; IPEndPoint iprm = (IPEndPoint)connection.RemoteEndPoint; this.Dispatcher.Invoke(new Action(() => { T2.AppendText("准备接受消息!\n"); })); Thread receiveThread = new Thread(ReceiveMessage); receiveThread.Start(connection); }
public void ReceiveMessage(object ClientSocket) { Socket myClientSocket = (Socket)ClientSocket; IPEndPoint iprm = (IPEndPoint)connection.RemoteEndPoint; while (true) { try { //通过clientsocket接收数据 int num = myClientSocket.Receive(result); //System.Windows.MessageBox.Show(Encoding.ASCII.GetString(result, 0, num)); //TB_recv_1.Text = "sss"; this.Dispatcher.Invoke(new Action(() => { T2.AppendText(Encoding.Unicode.GetString(result, 0, num)); })); Thread sendThread = new Thread(SendMessage); sendThread.Start(myClientSocket); // Message c = DealMsg1(Encoding.ASCII.GetString(result)); //c.msg2_tkt_ADc = iprm.Address.ToString(); //this.Dispatcher.Invoke(new Action(() => { TextBox2.AppendText(c.MMessage(c)); })); //string ssmg; // ssmg=c.ssMessage(c); //this.Dispatcher.Invoke(new Action(() => { TextBox4.AppendText(ssmg); })); // Byte[] ssmg1 = new byte[1024]; // ssmg1=Encoding.ASCII.GetBytes(ssmg); // int num1= myClientSocket.Send(ssmg1); } catch (Exception ex) { Console.WriteLine(ex.Message); //this.Dispatcher.Invoke(new Action(() => { TextBox3.AppendText("已断开连接"); })); //myClientSocket.Shutdown(SocketShutdown.Both); // myClientSocket.Close(); // break; } } }