コード例 #1
0
ファイル: Server.cs プロジェクト: kenny-gordon/Opixal
        public static void InitializeNetwork(int port)
        {
            //Console.WriteLine("Initializing Packets");
            Global.LogManager.LogInfo(message: "Initializing Packets", type: typeof(Server));
            ServerHandler.InitializePackets();

            serverSocket = new TcpListener(IPAddress.Any, port);
            serverSocket.Start();
            serverSocket.BeginAcceptTcpClient(new AsyncCallback(OnClientConnect), null);
            //Console.WriteLine("Server Started on {0}", serverSocket.LocalEndpoint);
            Global.LogManager.LogInfo(message: $"Server Started on {serverSocket.LocalEndpoint}", type: typeof(Server));
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: kenny-gordon/Opixal
        private void OnReceiveData(IAsyncResult asyncResult)
        {
            try
            {
                int length = stream.EndRead(asyncResult);
                if (length <= 0)
                {
                    CloseConnection();
                    return;
                }

                byte[] newBytes = new byte[length];
                Array.Copy(receiveBuffer, newBytes, length);
                ServerHandler.HandleData(connectionID, newBytes);
                stream.BeginRead(receiveBuffer, 0, socket.ReceiveBufferSize, OnReceiveData, null);
            }
            catch (Exception)
            {
                CloseConnection();
                return;
            }
        }