示例#1
0
        public void ReadCallback(string message)
        {
            SocketAction socketAction = SocketAction.Deserialize(message);

            switch (socketAction.SocketActions)
            {
            case SocketActions.ClientLogin:
                Username = socketAction.Message;
                Console.WriteLine($"Welcome {Username}!");
                Program.Server.JoinRoom(Username, Roomname);
                break;

            case SocketActions.ClientChat:
                if (Roomname != socketAction.Message)
                {
                    Program.Server.LeaveRoom(Username, Roomname);
                    Roomname = socketAction.Message;
                    Program.Server.JoinRoom(Username, Roomname);
                }
                break;

            case SocketActions.ClientGoodbye:
                Close();
                break;

            case SocketActions.ClientSendMessage:
                MessageControl(socketAction.Message);
                break;
            }
        }
示例#2
0
        public async Task <int> SendMessage(SocketAction message)
        {
            await StreamWriter.WriteLineAsync(message.Serialize());

            await StreamWriter.FlushAsync();

            return(1);
        }