示例#1
0
        static ClientReceivers()
        {
            NetworkReceivers.RegisterClientReceiver("print", (sender, packet) =>
            {
                Console.WriteLine(packet.ReadString());
            });

            NetworkReceivers.RegisterClientReceiver("serverJoinInfo", (sender, packet) =>
            {
                Console.WriteLine("Connected to " + packet.ReadString());
            });
        }
示例#2
0
        private void ReceiveCallback(IAsyncResult result)
        {
            networkStream.EndRead(result);

            if (!IsConnected())
            {
                Disconnect();
            }

            try
            {
                NetworkReceivers.ServerReceive(this, new NetworkPacket(dataBuffer));
                networkStream.BeginRead(dataBuffer, 0, dataBuffferSize, ReceiveCallback, null);
            }
            catch
            {
            }
        }