Ejemplo n.º 1
0
        private void waitClient(object o)
        {
            ClientBuf clientPack = (ClientBuf)o;

            NetworkStream stream = clientPack.client.GetStream();

            byte[] buff = new byte[MAX_SOCKET_BUF];
            while (true)
            {
                int nBytes = 0;
                try {
                    nBytes = stream.Read(buff, 0, buff.Length);
                    if (nBytes == 0)
                    {
                        break;
                    }
                }
                catch (Exception e) { LOG.echo(e.ToString()); break; }

                clientPack.buf.Push(buff, nBytes);

                QueuePack info = new QueuePack();
                info.ClientID = clientPack.id;
                info.buf      = clientPack.buf;
                info.type     = NetType.DATA;
                info.ipAddr   = clientPack.address;
                mQueue.Enqueue(info);

                mMRE.Set();
            }

            stream.Close();
            CloseClient(clientPack.id);
        }
Ejemplo n.º 2
0
        public static void Open()
        {
            string strConn = "Server=localhost;Database=test;Uid=root;Pwd=root;SslMode=none;";

            mConn = new MySqlConnection(strConn);

            try { mConn.Open(); }
            catch (Exception e) { LOG.echo(e.ToString()); }
        }
Ejemplo n.º 3
0
        private void Run_waitClient(object o)
        {
            TcpClient     client  = (TcpClient)o;
            string        ipAddr  = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
            NetworkStream stream  = client.GetStream();
            FifoBuffer    fifoBuf = new FifoBuffer(MAX_FIFO_BUF);

            byte[] buff = new byte[MAX_SOCKET_BUF];
            while (true)
            {
                int nBytes = 0;
                try
                {
                    nBytes = stream.Read(buff, 0, buff.Length);
                    if (nBytes == 0)
                    {
                        break;
                    }
                }
                catch (Exception e) { LOG.echo(e.ToString()); break; }

                fifoBuf.Push(buff, nBytes);

                while (true)
                {
                    int        len = fifoBuf.GetSize();
                    byte[]     buf = fifoBuf.readSize(len);
                    ICD.HEADER msg = ICD.HEADER.ConvertBytesToICDMessage(buf);
                    if (msg == null)
                    {
                        break;
                    }

                    fifoBuf.Pop(msg.msgSize);
                    OnProcRead?.Invoke(ipAddr, msg);
                }
            }

            fifoBuf.Clear();
            stream.Close();
            CloseClient(ipAddr);
        }