Example #1
0
        /// <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;
                }
            }
        }
Example #4
0
        /// <summary>
        /// 发送一个buffer
        /// </summary>
        /// <param name="buffer">数据包</param>
        public void SendBuffer(byte[] buffer)
        {
            JustArgs args = new JustArgs();

            args.buffer = buffer;
            this.SendJust(args);
        }
Example #5
0
        /// <summary>
        /// 发送Just数据包
        /// </summary>
        /// <param name="just">数据包</param>
        public void SendJust(Just.Just just)
        {
            JustArgs args = new JustArgs();

            args.buffer = just.get();
            this.SendJust(args);
        }
Example #6
0
        /// <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);
        }
Example #7
0
        /// <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>
 /// 发送
 /// </summary>
 /// <param name="args"></param>
 public void LowLevelSend(JustAdapter adapter, JustArgs args)
 {
     Console.WriteLine("发送一个数据包");
     SerialPort port = adapter.TAG as SerialPort;
 }
Example #12
0
        /// <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();
        }
Example #13
0
 /// <summary>
 /// 发送一个buffer
 /// </summary>
 /// <param name="buffer">数据包</param>
 public void SendBuffer(byte[] buffer)
 {
     JustArgs args = new JustArgs();
     args.buffer = buffer;
     this.SendJust(args);
 }
Example #14
0
 /// <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);
 }
Example #15
0
 /// <summary>
 /// 发送Just数据包
 /// </summary>
 /// <param name="just">数据包</param>
 public void SendJust(Just.Just just)
 {
     JustArgs args = new JustArgs();
     args.buffer = just.get();
     this.SendJust(args);
 }