C#源代码 如何实现点对点的聊天,一个比较详尽的实现点对点聊天的源代码 核心代码: string MyMessage= this.textBox2.Text+":"+this.richTextBox1.Text+"\n"; //根据目标计算机地址建立连接 TcpClient MyTcpClient = new TcpClient(this.textBox1.Text, 888); //获得用于网络访问的数据流 NetworkStream MyTcpStream =MyTcpClient.GetStream(); StreamWriter MyStream = new StreamW riter(MyTcpStream); //将字符串写入流 MyStream.Write(MyMessage); //将缓冲数据写入基础流 MyStream.Flush(); //关闭网络流 MyStream.Close(); MyTcpClient.Close(); this.richTextBox3.AppendText(this.richTextBox1.Text+"\n"); this.richTextBox1.Clear(); riter(MyTcpStream); //将字符串写入流 MyStream.Write(MyMessage); //将缓冲数据写入基础流 MyStream.Flush(); //关闭网络流 MyStream.Close(); MyTcpClient.Close(); this.richTextBox3.AppendText(this.richTextBox1.Text+"\n"); this.richTextBox1.Clear();