/// <summary> /// 发送线程 /// </summary> private void JustServiceSendThread() { JustArgs args = null; JustAdapter adapter = this.mAdapter; while (true) { Queue <JustArgs> argsQueue = this.argsQueue; args = null; if (argsQueue.Count > 0) { args = argsQueue.Dequeue(); } if (args == null) { mSendEvent.WaitOne(); continue; //args = argsQueue.Dequeue(); } adapter.mJustClientInterface.LowLevelSend(mAdapter, args); JustEventInterface JustEvent = adapter.mJustEventInterface; if (JustEvent != null) { JustEvent.OnSendEvent(adapter, args); } } }
/// <summary> /// 发送 /// </summary> /// <param name="args"></param> public void LowLevelSend(JustAdapter adapter, JustArgs args) { Console.WriteLine("发送一个数据包"); //Thread.Sleep(1000); UdpClient udpSocket = adapter.TAG as UdpClient; byte[] buf = args.buffer; adapter.LastEventType = JustEventType.Successful; try { udpSocket.Send(buf, buf.Length, adapter.RemoteAddress, adapter.RemotePort); } catch (TimeoutException e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Timeout; } catch (Exception e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Unknow; } }
/// <summary> /// 发送 /// </summary> /// <param name="args"></param> public void LowLevelSend(JustAdapter adapter, JustArgs args) { //Console.WriteLine("发送一个数据包"); //Thread.Sleep(1000); List <UdpClient> sockets = adapter.TAG as List <UdpClient>; byte[] buf = args.buffer; adapter.LastEventType = JustEventType.Successful; foreach (UdpClient udpSocket in sockets) { try { udpSocket.Send(buf, buf.Length, adapter.RemoteAddress, adapter.RemotePort); } catch (TimeoutException e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Timeout; } catch (Exception e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Unknow; } } }
/// <summary> /// 发送一个buffer /// </summary> /// <param name="buffer">数据包</param> public void SendBuffer(byte[] buffer) { JustArgs args = new JustArgs(); args.buffer = buffer; this.SendJust(args); }
/// <summary> /// 发送Just数据包 /// </summary> /// <param name="just">数据包</param> public void SendJust(Just.Just just) { JustArgs args = new JustArgs(); args.buffer = just.get(); this.SendJust(args); }
/// <summary> /// 发送Just数据包 /// </summary> /// <param name="just">数据包</param> public void SendJust(Just.Just just, object obj) { JustArgs args = new JustArgs(); args.buffer = just.get(); args.TAG = obj; this.SendJust(args); }
/// <summary> /// 发送Just数据包 /// </summary> /// <param name="args"></param> public void SendJust(JustArgs args) { JustAdapter adapter = this.mAdapter; if (adapter == null) { throw new JustException(""); } argsQueue.Enqueue(args); StartServiceThread(); this.mSendEvent.Set(); }
/// <summary> /// 发送 /// </summary> /// <param name="args"></param> public void LowLevelSend(JustAdapter adapter, JustArgs args) { Console.WriteLine("发送一个数据包"); TcpClient tcpSocket = new TcpClient(); byte[] buffer = null; adapter.LastEventType = JustEventType.Successful; try { buffer = args.buffer; tcpSocket.SendTimeout = adapter.SendTimeout; tcpSocket.ReceiveTimeout = adapter.ReceiveTimeout; tcpSocket.Connect(adapter.RemoteAddress, adapter.RemotePort); tcpSocket.GetStream().Write(buffer, 0, buffer.Length); tcpSocket.GetStream().Flush(); } catch (TimeoutException e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Timeout; } catch (Exception e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Unknow; } finally { try { tcpSocket.Close(); Console.WriteLine("关闭连接"); } catch (Exception e) { Console.WriteLine(e); } } }
/// <summary> /// 发送 /// </summary> /// <param name="args"></param> public void LowLevelSend(JustAdapter adapter, JustArgs args) { Console.WriteLine("发送一个数据包"); TcpClient tcpSocket = new TcpClient(); byte[] buffer = null; adapter.LastEventType = JustEventType.Successful; try { buffer = args.buffer; tcpSocket.SendTimeout = adapter.SendTimeout; tcpSocket.ReceiveTimeout = adapter.ReceiveTimeout; tcpSocket.Connect(adapter.RemoteAddress, adapter.RemotePort); tcpSocket.GetStream().Write(buffer, 0, buffer.Length); tcpSocket.GetStream().Flush(); } catch(TimeoutException e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Timeout; } catch (Exception e) { Console.WriteLine(e); adapter.LastEventType = JustEventType.Unknow; } finally { try { tcpSocket.Close(); Console.WriteLine("关闭连接"); } catch (Exception e) { Console.WriteLine(e); } } }
/// <summary> /// 发送 /// </summary> /// <param name="args"></param> public void LowLevelSend(JustAdapter adapter, JustArgs args) { Console.WriteLine("发送一个数据包"); SerialPort port = adapter.TAG as SerialPort; }
/// <summary> /// 发送Just数据包 /// </summary> /// <param name="args"></param> public void SendJust(JustArgs args) { JustAdapter adapter = this.mAdapter; if(adapter == null) { throw new JustException(""); } argsQueue.Enqueue(args); StartServiceThread(); this.mSendEvent.Set(); }