Пример #1
0
        static void Main(string[] args)
        {
            var customPackets = new List<IPacket>
            {
                new ExamplePacket()
            };

            var srv = new uNetServer(1337, new ServerSettings(new List<IPacket>(), false));

            srv.Initialize();

            srv.OnPeerConnected += (o, e) => Console.WriteLine("Peer connected from: " + e.Peer.RemoteEndPoint);
            srv.OnPeerDisconnected += (o, e) => Console.WriteLine("Peer disconnected from: " + e.Peer.RemoteEndPoint);
            srv.OnPacketReceived += (o, e) => Console.WriteLine("Received {0} bytes", e.RawPacketSize);
            srv.OnPacketSent += (o, e) => Console.WriteLine("Sent packet with ID: " + e.Packet.ID + " and size: " + e.RawPacketSize);

            Console.ReadLine();
        }
Пример #2
0
        public Peer(TcpClient client, uNetServer server, ServerSettings settings)
        {
            Client = client;
            RemoteEndPoint = Client.Client.RemoteEndPoint;
            BufferSize = settings.ReceiveBufferSize;

            if (settings.UseSSL)
            {
                NetStream = new SslStream(Client.GetStream(), true);
                (NetStream as SslStream).AuthenticateAsServer(new X509Certificate(File.ReadAllBytes(settings.SSLCertLocation)));
            }
            else
                NetStream = Client.GetStream();

            Processor = new PacketProcessor(uNetServer.Settings);
            Server = server;

            ReadAsync();
        }
Пример #3
0
        public Peer(TcpClient client, uNetServer server, ServerSettings settings)
        {
            Client         = client;
            RemoteEndPoint = Client.Client.RemoteEndPoint;
            BufferSize     = settings.ReceiveBufferSize;

            if (settings.UseSSL)
            {
                NetStream = new SslStream(Client.GetStream(), true);
                (NetStream as SslStream).AuthenticateAsServer(new X509Certificate(File.ReadAllBytes(settings.SSLCertLocation)));
            }
            else
            {
                NetStream = Client.GetStream();
            }

            Processor = new PacketProcessor(uNetServer.Settings);
            Server    = server;

            ReadAsync();
        }