private void RecieveData(byte[] result, IAsyncResult asyResult)
        {
            BaseMessage message = null;

            switch (result[0])
            {
            case (byte)MTMessageType.Logon:
            case (byte)MTMessageType.Logout:
                message = new LogonMessage();
                break;

            case (byte)MTMessageType.DataPackage:
            case (byte)MTMessageType.EndMessage:
                message = new DataMessage();
                break;

            case (byte)MTMessageType.KeepAlive:
                break;

            default:
                break;
            }

            message?.ConvertFromBytes(result);
            RecieveDataCompleteAction?.Invoke(message);
        }
예제 #2
0
        private BaseMessage RecieveData(byte[] result)
        {
            BaseMessage message = null;

            switch (result[0])
            {
            case (byte)MTMessageType.Logon:
            case (byte)MTMessageType.Logout:
                message = new LogonMessage();
                break;

            case (byte)MTMessageType.DataPackage:
            case (byte)MTMessageType.EndMessage:
                message = new DataMessage();
                break;

            case (byte)MTMessageType.KeepAlive:
                break;

            default:
                break;
            }
            message.ConvertFromBytes(result);
            return(message);
        }
        private void RecieveData(byte[] result, IAsyncResult asyResult, Socket clientSocket)
        {
            int readCount = 0;

            try
            {
                readCount = clientSocket.EndReceive(asyResult);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            BaseMessage message = null;

            switch (result[0])
            {
            case (byte)MTMessageType.Logon:
            case (byte)MTMessageType.Logout:
                message = new LogonMessage();

                break;

            case (byte)MTMessageType.DataPackage:
            case (byte)MTMessageType.EndMessage:
                message = new DataMessage();
                break;

            case (byte)MTMessageType.KeepAlive:
                break;

            default:
                break;
            }

            message?.ConvertFromBytes(result);
            if (message is LogonMessage)
            {
                Clients[(message as LogonMessage).LogonID] = clientSocket;
            }
            Console.WriteLine(message?.MessageType.ToString());
            RecieveDataCompleteAction?.Invoke(message);
            //clientSocket.Send(Encoding.UTF8.GetBytes(PASSED.ToString()));
            if (message != null && message.MessageType == MTMessageType.Logout)
            {
                clientSocket.Shutdown(SocketShutdown.Both);
                clientSocket.Close();
            }
        }