示例#1
0
        /// <summary>
        /// Check new connections from other world
        /// </summary>
        public async Task CheckNewConnectionAsync()
        {
            var newConnection = await _tcpListener.AcceptTcpClientAsync();

            var connectionUser = new ConnectionModel
            {
                TcpSocket = newConnection
            };

            var connection = new Connection
            {
                User = connectionUser
            };

            CurrentConnections.Add(connection);

            connection.OnReceivedMessage    += Connection_OnReceivedMessage;;
            connection.OnDisconnected       += Connection_OnDisconnected;
            connection.OnReceivedCommand    += Connection_OnReceivedCommand;
            connection.OnReceivedVideoFrame += Connection_OnReceivedVideoFrame;
            connection.OnStartSendingVideo  += Connection_OnStartSendingVideo;
            connection.OnStopSendingVideo   += Connection_OnStopSendingVideo;

            connection.StartReceiveResponses();
        }
示例#2
0
        public void Send(string name)
        {
            string connectionId = Context.ConnectionId;

            string userName = name;

            if (userName != null && userName.Length >= 1)
            {
                var u = new Users()
                {
                    ConnectionId = connectionId,
                    UserName     = userName
                };

                if (u.ConnectionId != null && !CurrentConnections.Contains(u))
                {
                    CurrentConnections.Add(u);
                }
            }
            //Clients.AllExcept(CurrentConnections.Where(x => x.ConnectionId == Context.ConnectionId).Select(x => x.ConnectionId).FirstOrDefault());
            Clients.All.broadcastMessage(name);
            Clients.Caller.renderGame();
        }