SagaLib.NetIO.NetIO C# (CSharp) Method

NetIO() public method

Create a new netIO class using a given socket.
public NetIO ( Socket sock, Packet>.Dictionary commandTable, SagaLib.Client client, ClientManager manager ) : System
sock System.Net.Sockets.Socket The socket for this netIO class.
commandTable Packet>.Dictionary
client SagaLib.Client
manager ClientManager
return System
        public NetIO(Socket sock, Dictionary<ushort, Packet> commandTable, Client client ,ClientManager manager)
        {
            this.sock = sock;
            this.stream = new NetworkStream(sock);
            this.commandTable = commandTable;
            this.client = client;
            this.currentClientManager = manager;

            this.callbackSize = new AsyncCallback(this.ReceiveSize);
            this.callbackData = new AsyncCallback(this.ReceiveData);
            this.nlock = new ReaderWriterLock();
            // Use the static key untill the keys have been exchanged
            this.clientKey = new byte[16];
            Encryption.StaticKey.CopyTo(this.clientKey, 0);
            this.serverKey = new byte[16];
            Encryption.StaticKey.CopyTo(this.serverKey, 0);

            this.isDisconnected = false;

            // Receive the size of the next packet and call ReceiveSize when finished
            if (sock.Connected)
            {
                try { stream.BeginRead(buffer, 0, 2, this.callbackSize, null); }
                catch (Exception ex) {
                    Logger.ShowError(ex, null);
                    try//this could crash the gateway somehow,so better ignore the Exception
                    {
                        this.Disconnect();
                    }
                    catch (Exception)
                    {
                    }
                    Logger.ShowWarning("Invalid packet head from:" + sock.RemoteEndPoint.ToString(), null);
                    return;
                }
            }
            else { this.Disconnect(); return; }
        }

Same methods

NetIO::NetIO ( Socket sock, Packet>.Dictionary commandTable, SagaLib.Client client, bool isgateway ) : System