Пример #1
0
        public static void InitServer()
        {
            Text.WriteLine("Loading server ...", TextType.DEBUG);

            int start = GetTickCount();

            InitClients();
            ServerHandleData.InitPacketsFromClient();
            ServerTcp.InitServer();

            int end = GetTickCount();

            Text.WriteLine("Server loaded in {0} ms", TextType.DEBUG, end - start);
        }
Пример #2
0
        private static void HandleChatMessageFromClient(int connectionId, byte[] data)
        {
            try
            {
                //Creates a new instance of the buffer to read out the packet.
                ByteBuffer buffer = new ByteBuffer();
                //writes the packet into a list to make it avaiable to read it out.
                buffer.WriteBytes(data);
                //Todo INFO: You always have to read out the data as you sent it.
                //In this case you always have to first to read out the packet identifier.
                int packetIdentify = buffer.ReadInteger();
                //In the server side you now send a string as next so you have to read out the string as next.
                string msg = buffer.ReadString();

                ServerTcp.SendChatMessageToClient(connectionId, msg);

                //print out the string msg you did send from the server.
                Text.WriteLine($"Got Packet with identifier {packetIdentify} with message: {msg} from connection with connection id: {connectionId}", TextType.INFO);
            }
            catch (Exception e)
            {
                Text.WriteLine($"Error occured in ServerHandleData:HandleChatMessageFromClient  with message {e.Message}", TextType.ERROR);
            }
        }