////// 监听并返回数据 /// ///public static void TcpSocketReceive() { try { string ip = "127.0.0.1"; int TcpPort = 8080; IPEndPoint ipend = new IPEndPoint(IPAddress.Parse(ip), TcpPort); Socket sc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sc.Bind(ipend); Socket acc; sc.Listen(1); acc = sc.Accept(); byte[] buff = new byte[1024]; int recbyte = acc.Receive(buff, buff.Length, 0); string reciveval = Encoding.UTF8.GetString(buff, 0, recbyte); //返回数据 string message = ObtainDataTransmission.GetReturnMsg(); byte[] bt = Encoding.UTF8.GetBytes(message); acc.Send(bt, bt.Length, 0); acc.Dispose(); sc.Dispose(); acc.Close(); sc.Close(); } catch (Exception ex) { ErrorLosCommon.Write(ex.Message, ex.ToString()); } }