Beispiel #1
0
        private void FireDataReceived(Byte[] data, System.Net.EndPoint ep, System.Net.EndPoint epLocal, TcpSession tcpSession)
        {
            EventHandler <DataReceivedEventArgs> h = DataReceived;

            if (h != null)
            {
                h(this, new DataReceivedEventArgs(data, ep, epLocal, tcpSession));
            }
        }
Beispiel #2
0
 private static void AddSession(TcpSession session)
 {
     lock (_sessionList) {
         _sessionList.Add(session);
     }
 }
Beispiel #3
0
        private void StreamListener(TcpSession soTcp)
        {
            try {
                NetworkStream stream = soTcp.Stream;

                byte[] bytes  = new byte[1163];
                int    offset = 0;
                int    messageSize;

                //  Start by sending the capability message
                byte[] data = { 0x10, 0xE1, 0x40 };
                stream.Write(data, 0, data.Length);

                while (true)
                {
                    int i = stream.Read(bytes, offset, bytes.Length - offset);
                    i += offset;

                    while (i > 0)
                    {
                        //  Do I have a full record?

                        int dataSize = (bytes[0] >> 4) & 0xf;
                        switch (dataSize)
                        {
                        case 13:
                            messageSize = bytes[1] + 13 + 3;
                            break;

                        case 14:
                            messageSize = (bytes[1] * 256 + bytes[2]) + 269 + 4;
                            break;

                        case 15:
                            messageSize = ((bytes[1] * 256 + bytes[2]) * 256 + bytes[3]) * 256 + bytes[4] + 65805 + 6;
                            break;

                        default:
                            messageSize = dataSize + 2;
                            break;
                        }
                        messageSize += (bytes[0] & 0xf); // Add token buffer

                        if (i >= messageSize)
                        {
                            byte[] message = new byte[messageSize];
                            Array.Copy(bytes, message, messageSize);
                            Array.Copy(bytes, messageSize, bytes, 0, i - messageSize);
                            offset = i - messageSize;
                            i     -= messageSize;

                            FireDataReceived(message, soTcp.EndPoint, soTcp);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception e) {
                Console.WriteLine("StreamListener --> " + e.ToString());
            }
        }
Beispiel #4
0
 public QueueItem(TcpSession session, byte[] data)
 {
     _data    = data;
     _session = session;
 }