コード例 #1
0
ファイル: TCPPacket.cs プロジェクト: JessicaBarclay/Cosmos
        /// <summary>
        /// TCP handler.
        /// </summary>
        /// <param name="packetData">Packet data.</param>
        /// <exception cref="sys.ArgumentOutOfRangeException">Thrown on fatal error (contact support).</exception>
        /// <exception cref="sys.IO.IOException">Thrown on IO error.</exception>
        /// <exception cref="sys.ArgumentException">Thrown on fatal error (contact support).</exception>
        /// <exception cref="sys.OverflowException">Thrown if packetData array length is greater than Int32.MaxValue.</exception>
        internal static void TCPHandler(byte[] packetData)
        {
            var packet = new TCPPacket(packetData);

            if (packet.CheckCRC())
            {
                var client = TcpClient.GetClient(packet.DestinationPort);
                if (client != null)
                {
                    client.StateMachine.ReceiveData(packet);
                    return;
                }

                var listener = TcpListener.GetListener(packet.DestinationPort);
                if (listener != null)
                {
                    listener.StateMachine.ReceiveData(packet);
                    return;
                }
            }
            else
            {
                Global.mDebugger.Send("Checksum incorrect! Packet passed.");
            }
        }
コード例 #2
0
        /// <summary>
        /// TCP handler.
        /// </summary>
        /// <param name="packetData">Packet data.</param>
        /// <exception cref="sys.ArgumentOutOfRangeException">Thrown on fatal error (contact support).</exception>
        /// <exception cref="sys.IO.IOException">Thrown on IO error.</exception>
        /// <exception cref="sys.ArgumentException">Thrown on fatal error (contact support).</exception>
        /// <exception cref="sys.OverflowException">Thrown if packetData array length is greater than Int32.MaxValue.</exception>
        internal static void TCPHandler(byte[] packetData)
        {
            var packet = new TCPPacket(packetData);

            if (packet.CheckCRC())
            {
                var connection = Tcp.GetConnection(packet.DestinationPort, packet.SourcePort, packet.DestinationIP, packet.SourceIP);

                if (connection != null)
                {
                    connection.ReceiveData(packet);
                }
            }
            else
            {
                Global.mDebugger.Send("Checksum incorrect! Packet passed.");
            }
        }