public void Start() { exit = false; IPAddress localAddr = IPAddress.Parse(NetUtil.LocalIp()); server = new TcpListener(localAddr, NetUtil.PORT_FILE_TRANSFER_SERVER); server.Start(); while (!exit) { TcpClient client = server.AcceptTcpClient(); ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProc), client); } }
/// <summary> /// 获取手机的IP地址 /// </summary> /// <param name="index"></param> /// <returns></returns> public string GetPhoneIP(int index) { string ip = string.Empty; TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse(NetUtil.GetStationIp(0)), NetUtil.PORT_LITE_DATA_SERVER); using (NetworkStream stream = client.GetStream()) { string request = "TargetIp " + index; byte[] requestBuffer = System.Text.Encoding.UTF8.GetBytes(request); stream.Write(requestBuffer, 0, requestBuffer.Length); byte[] respBuffer = new byte[1024]; int len = stream.Read(respBuffer, 0, respBuffer.Length); if (len > 0) { ip = System.Text.Encoding.UTF8.GetString(respBuffer, 0, len); } } client.Close(); return(ip); }
/// <summary> /// 流程运行完成事件 /// </summary> /// <param name="index"></param> /// <returns></returns> public bool SendCompleteFlag(int index) { bool result = false; TcpClient client = new TcpClient(); client.Connect(IPAddress.Parse(NetUtil.GetStationIp(0)), NetUtil.PORT_LITE_DATA_SERVER); using (NetworkStream stream = client.GetStream()) { string request = "Complete " + index; byte[] requestBuffer = System.Text.Encoding.UTF8.GetBytes(request); stream.Write(requestBuffer, 0, requestBuffer.Length); byte[] respBuffer = new byte[1024]; int len = stream.Read(respBuffer, 0, respBuffer.Length); if (len > 0) { string response = System.Text.Encoding.UTF8.GetString(respBuffer, 0, len); result = true; } } client.Close(); return(result); }