日期:2014-05-17 浏览次数:20803 次
//这是接收的 private void RecvData() { try { TcpListener tcpList = new TcpListener(IPAddress.Parse(ipName), port); tcpList.Start(); sockets = tcpList.AcceptSocket(); ns = new NetworkStream(sockets); BitmapImage bitImage = new BitmapImage(); bitImage.BeginInit(); bitImage.StreamSource = ns; bitImage.EndInit(); image2.Source = bitImage; } catch (Exception es) { es.Message.ToString(); } } //这是发送 private void SendData() { try { myclient = new TcpClient(ipName, port); myns = myclient.GetStream(); mysw = new BinaryWriter(myns); mysw.Write(result); mysw.Flush(); myns.Flush(); mysw.Close(); myns.Close(); myclient.Close(); } catch (Exception es) { es.Message.ToString(); } }