Пример #1
0
        public override Task OnConnectedAsync()
        {
            ConnectionData connectionData = new ConnectionData();

            connectionData.ConnectionId   = Context.ConnectionId;
            connectionData.ConnectionTime = DateTime.Now;
            connectionData.PeerCode       = (int)PeersEnum.PeerOne;

            var httpContext = Context.GetHttpContext();

            connectionData.Payload = $"Local Port: {httpContext.Connection.LocalPort} \n" +
                                     $" Local IP Address: {httpContext.Connection.LocalIpAddress} \n" +
                                     $" Connection Id: { httpContext.Connection.Id} \n" +
                                     $" Project Server Name: PeerOneHub";
            ConnectionList.AddUser(connectionData);

            //share this peers' info with the connected client
            Clients.All.SendAsync("ActiveConnections", ConnectionList.GetActiveConnections());

            //share this peer's TransactionPool
            Clients.All.SendAsync("ReceiveTransactions", (int)PeersEnum.PeerOne, TransactionPool.Instance.Transactions);

            //share this peers' blockchain with the connected client
            return(Clients.All.SendAsync("ReceiveCurrentBlockchain", (int)PeersEnum.PeerOne, _blockchain.Chain));
        }
Пример #2
0
        private void ConnectionLoop()
        {
            serverListener.Start();

            while (true)
            {
                var connectedClient = serverListener.AcceptTcpClient();
                var client          = GetClient(connectedClient);
                if (client != null)
                {
                    connList.AddUser(client);
                }
                Thread.Sleep(20); //+++
            }
        }
Пример #3
0
        public override Task OnConnectedAsync()
        {
            ConnectionData connectionData = new ConnectionData();

            connectionData.ConnectionId   = Context.ConnectionId;
            connectionData.ConnectionTime = DateTime.Now;
            var httpContext = Context.GetHttpContext();

            connectionData.Payload = $"Local Port: {httpContext.Connection.LocalPort} \n" +
                                     $" Local IP Address: {httpContext.Connection.LocalIpAddress} \n" +
                                     $" Connection Id: { httpContext.Connection.Id} \n" +
                                     $" Project Server Name: ChatHub";
            ConnectionList.AddUser(connectionData);

            return(Clients.All.SendAsync("ActiveConnections", ConnectionList.GetActiveConnections()));
        }