private void EndAccept(IAsyncResult ar)
        {
            var listener = ListenSocket.EndAccept(ar);
            var connId   = Guid.NewGuid().ToString();
            var args     = ClientPool.Take();

            args.AcceptSocket = listener;
            args.UserToken    = ServerConnectionFactory.Create(this, connId);
            args.LastResponse = DateTime.UtcNow.AddMinutes(1);
            listener.BeginReceive(_receiveBuffer, 0, _receiveBuffer.Length, SocketFlags.None, EndReceive, args);
            ListenSocket.BeginAccept(EndAccept, ListenArgs);
            ClientsToSocket.TryAdd(connId, args);
            OnClientConnectedInvoke((ServerConnectionBase)args.UserToken);
        }
Ejemplo n.º 2
0
        public void CreatePlugin()
        {
            var plugin  = new TestApplication();
            var Clients = new List <PeerBase>();
            var tcp     = plugin.GetTransportByName("TCPIPV4");

            plugin.RegisterReceiveCommand(tcp, new LogInRequest());

            var connection = ServerConnectionFactory.Create(plugin.GetTransportByName("TCPIPV4"), Guid.NewGuid().ToString());
            var byteconn   = connection as ServerConnection <byte[]>;

            byteconn.DeSerializer = new ProtoBufGenericSerializer <LogInRequest>();

            plugin.OnClientConnected += (sender, conn) =>
            {
                var peer = new TestPeer(conn);
                Clients.Add(peer);
            };

            plugin.RaiseClientConnected(connection);
            plugin.RaisePacketReceived(connection);
        }