public void HandleDevice(Object obj) { TcpClient client = (TcpClient)obj; stream = client.GetStream(); Packet packet = new Packet(); //pachetul primit de la client Packet responsePacket = new Packet(); //pachetul pe care il vom trimite in urma cerererii clientului try { while (Running()) { packet = SerializeControl.ReadObject(stream, _client.Client.RemoteEndPoint.ToString()); //citesc pachetul primit de la client folosind serializare TCP _log.WriteLog(Thread.CurrentThread.ManagedThreadId + ": Received: " + packet._data + "\n"); Command.Command command = new Command.Command(dataController, packet); responsePacket = command.Execute(); // am pregatit raspunsul _log.WriteLog(Thread.CurrentThread.ManagedThreadId + ": Sent: " + responsePacket._data + "\n"); SerializeControl.WriteObject(stream, responsePacket, _client.Client.RemoteEndPoint.ToString()); //trimit raspunsul clientului folosind serializare TCP } } catch (Exception e) { _log.WriteLog("Exception: " + e.ToString()); client.Close(); } }
// 发送请求的方法 public void OnClick() { Console.WriteLine("点击功能键:"); if (command != null) { command.Execute(); } }