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(); }
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(); }
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(); }