Exemplo n.º 1
0
        public ChatServer()
        {
            scheduler = new TaskScheduler();
            tcpLayer  = new ChatTcpLayer(false, scheduler, PacketUtilities.PACKET_SIZE);

            readCheck  = new List <Socket>();
            writeCheck = new List <Socket>();
            errorCheck = new List <Socket>();

            clientsConnected    = new List <ChatClientData>();
            clientsConnectedDic = new Dictionary <Socket, ChatClientData>();

            activeRoomsByName = new Dictionary <string, ChatRoom>();

            packetsSupportedMap = new PacketMap <Packet, ChatClientData>();
            packetsSupportedMap[Protocol.ASK_ALL_CONNECTED] = this.AskAllConnectedReceived;
            packetsSupportedMap[Protocol.MESSAGE_SENT]      = this.MessageSentReceived;
            packetsSupportedMap[Protocol.QUIT] = this.QuitReceived;
            packetsSupportedMap[Protocol.JOIN] = this.JoinReceived;

            packetsSupportedMap[Protocol.CREATE_ROOM]   = this.CreateRoomReceived;
            packetsSupportedMap[Protocol.CLOSE_ROOM]    = this.CloseRoomReceived;
            packetsSupportedMap[Protocol.INVITE_CLIENT] = this.InviteClientReceived;
            packetsSupportedMap[Protocol.LEAVE_ROOM]    = this.LeaveRoomReceived;
        }
Exemplo n.º 2
0
        public ChatClient(string server, int port, string clientName, bool logEnabled = false)
        {
            scheduler = new TaskScheduler();
            tcpLayer  = new ChatTcpLayer(true, this.scheduler, PacketUtilities.PACKET_SIZE);

            tcpLayer.SetServer(server, port);

            this.clientName = clientName;
            this.logEnabled = logEnabled;

            JoinedRooms = new Dictionary <string, ChatRoom>();

            packetsSupportedMap = new PacketMap <Packet, object>();
            packetsSupportedMap[Protocol.CLIENT_JOINED]     = ReceiveClientJoined;
            packetsSupportedMap[Protocol.CLIENT_LEFT]       = ReceiveClientLeft;
            packetsSupportedMap[Protocol.MESSAGE_RECEIVED]  = ReceiveMessageReceived;
            packetsSupportedMap[Protocol.GET_ALL_CONNECTED] = ReceiveGetAllConnected;
            packetsSupportedMap[Protocol.SERVER_CLOSED]     = ReceiveServerClosed;

            packetsSupportedMap[Protocol.ROOM_CREATED] = ReceiveRoomCreated;
            packetsSupportedMap[Protocol.ROOM_CLOSED]  = ReceiveRoomClosed;
            packetsSupportedMap[Protocol.ROOM_JOINED]  = ReceiveRoomJoined;
            packetsSupportedMap[Protocol.ROOM_LEFT]    = ReceiveRoomLeft;
        }