Exemplo n.º 1
0
        public Server(ManualLogSource log, PeerMessageList <TServer> messages, byte channelsCount, IServerEvents <TServer> events, Version version, IPAddress ipv4, IPAddress ipv6, ushort port)
        {
            var listenerEvents = new ServerListenerEvents <TServer>((TServer)this, log, events, version);

            _listener = new MessageListener <TServer>((TServer)this, messages, log, listenerEvents);

            _peer = new SelfPeer <TServer>(channelsCount, _listener);
            if (!_peer.Manager.Start(ipv4, ipv6, port))
            {
                throw new InvalidOperationException($"Could not bind socket. IPv4: {ipv4}; IPv6: {ipv6}; port: {port}");
            }
        }
Exemplo n.º 2
0
        public Client(ManualLogSource log, PeerMessageList <TClient> messages, byte channelsCount, IClientEvents <TClient> events, Version version, IPEndPoint endpoint, Action <NetDataWriter> payload = null)
        {
            var listenerEvents = new ClientListenerEvents <TClient>((TClient)this, log, events);

            _listener = new MessageListener <TClient>((TClient)this, messages, log, listenerEvents);

            _peer = new SelfPeer <TClient>(channelsCount, _listener);

            using (WriterPool.Instance.Borrow(out var writer))
            {
                writer.Put(version);
                payload?.Invoke(writer);

                _peer.Manager.Start();
                _peer.Manager.Connect(endpoint, writer);
            }
        }