using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Sockets; using System.Threading; using System.Net; using System.IO; namespace WindowsFormsApplication3 { public partial class Form1 : Form { TcpClient tcpc = new TcpClient(); ASCIIEncoding asce = new ASCIIEncoding(); NetworkStream ns; BinaryReader br; BinaryWriter bw; public void cli() { try { tcpc.Connect(IPAddress.Parse("127.0.0.1"), 5000); ns = tcpc.GetStream(); br = new BinaryReader(ns); bw = new BinaryWriter(ns); string st = br.ReadString(); MessageBox.Show("srever send this message:" + st); } catch { } } public Form1() { InitializeComponent(); Thread thread = new Thread(new ThreadStart(cli)); thread.Start(); } private void button1_Click(object sender, EventArgs e) { bw.Write(textBox1.Text); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Net.Sockets; using System.IO; using System.Threading; using System.Net; namespace WindowsFormsApplication2 { public partial class server : Form { BinaryReader br; BinaryWriter bw; Socket soc; NetworkStream ns; public void dolisten(){ try { IPAddress ip = IPAddress.Parse("127.0.0.1"); TcpListener tcpl = new TcpListener(ip, 5000); tcpl.Start(); soc = tcpl.AcceptSocket(); ns = new NetworkStream(soc); br = new BinaryReader(ns); bw = new BinaryWriter(ns); string ss = br.ReadString(); MessageBox.Show("client send this message" + ss); } catch { MessageBox.Show("error"); } } public server() { InitializeComponent(); Thread thread = new Thread(new ThreadStart(dolisten)); thread.Start(); } private void button1_Click(object sender, EventArgs e) { string sss = textBox1.Text; bw.Write(sss); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)