Beispiel #1
0
        public MartialSession(Socket socket)
        {
            m_socket = socket;
            m_socket.NoDelay = false;
            m_socket.ReceiveBufferSize = 0xFFFF;
            m_socket.SendBufferSize = 0xFFFF;

            m_locker = new object();
            m_disposed = false;

            Label = ((IPEndPoint)(m_socket.RemoteEndPoint)).Address.ToString();

            m_sendCipher = new MartialCipher(MartialCipher.TransformDirection.Encrypt);
            m_recvCipher = new MartialCipher(MartialCipher.TransformDirection.Decrypt);

            WaitForData(true, 4); // cause of Martial Packet Header size
        }
Beispiel #2
0
        public void Dispose()
        {
            if(!m_disposed)
            {
                lock(m_locker)
                {
                    if(!m_disposed)
                    {
                        m_disposed = true;

                        try
                        {
                            m_socket.Shutdown(SocketShutdown.Both);
                        }
                        catch(SocketException)
                        {

                        }
                        m_socket.Close();

                        if(m_recvCipher != null)
                            m_recvCipher.Dispose();

                        m_offset = 0;
                        m_buffer = null;

                        m_sendCipher = null;
                        m_recvCipher = null;

                        OnDisconnected();
                    }
                }
            }
        }