基于TCP协议的远程屏幕监控两台以上客户端的远程屏幕程序设计
public void getRemote3() { IPAddressip = IPAddress.Parse("127.0.0.1"); tcp = new TcpListener(ip, 8083); tcp.Start(); socket =tcp.AcceptSocket(); ns = new NetworkStream(socket); sr = new StreamReader(ns); sw = new StreamWriter(ns); if(socket.Connected) { try { while (true) { byte[] b = new byte[1024 * 256];//设置接收大小 int i = this.socket.Receive(b);//接收 //把byte[]转化成内存流,再把内存流转化成Image System.Drawing.Image myimage =System.Drawing.Image.FromStream(new MemoryStream(b)); PB5.Image =myimage;//显示 this.PB5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; //MessageBox.Show("显示成功!server"); } } catch (Exceptionex) { this.tcp.Stop(); MessageBox.Show("4号窗口捕获捕获屏幕出错!server" ex.Message); } } }
评论