public void Start(int port = 0)
    {
        _listenning     = false;
        _newConnections = new Queue <NewConnection>();
        _clients        = new Dictionary <int, ORTCPClient>();

        if (port != 0)
        {
            StartListening(port);
        }
        else
        {
            StartListening();
        }

        Observable
        .Interval(TimeSpan.FromSeconds(1))
        .Where(_ => _newConnections.Count > 0)
        .Subscribe(_ =>
        {
            //Debug.Log(Thread.CurrentThread.ManagedThreadId);
            NewConnection newConnection = _newConnections.Dequeue();
            ORTCPClient client          = ORTCPClient.CreateInstance("ORMultiServerClient", newConnection.tcpClient, this, port);

            int clientID = SaveClient(client);
            ORTCPEventParams eventParams = new ORTCPEventParams();
            eventParams.eventType        = ORTCPEventType.Connected;
            eventParams.client           = client;
            eventParams.clientID         = clientID;
            eventParams.socket           = newConnection.tcpClient;
            Console.BackgroundColor      = ConsoleColor.Cyan;
            Console.ForegroundColor      = ConsoleColor.Black;
            Console.WriteLine("[TCPServer] New client connected");
        });
    }
    private void Start()
    {
        _listenning     = false;
        _newConnections = new Queue <NewConnection>();
        _clients        = new Dictionary <int, ORTCPClient>();
        StartListening();

        Observable
        .EveryUpdate()
        .Where(_ => _newConnections.Count > 0)
        .Subscribe(_ =>
        {
            //Debug.Log(Thread.CurrentThread.ManagedThreadId);
            NewConnection newConnection = _newConnections.Dequeue();
            ORTCPClient client          = ORTCPClient.CreateInstance("ORMultiServerClient", newConnection.tcpClient, this);


            int clientID = SaveClient(client);
            ORTCPEventParams eventParams = new ORTCPEventParams();
            eventParams.eventType        = ORTCPEventType.Connected;
            eventParams.client           = client;
            eventParams.clientID         = clientID;
            eventParams.socket           = newConnection.tcpClient;
            if (verbose)
            {
                print("[TCPServer] New client connected");
            }
        });
    }
Ejemplo n.º 3
0
    private void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(this.gameObject);
        }
        else
        {
            _instance = this;
        }
        //debug binding
        Observable.EveryUpdate()
        .Select(_ => GameManager.TargetObject_External)
        .DistinctUntilChanged()
        .Subscribe(_ => verbose = (GameManager.TargetObject_External & TargetObject.TCP) == TargetObject.TCP)
        .AddTo(gameObject);

        _listenning     = false;
        _newConnections = new Queue <NewConnection>();
        _clients        = new Dictionary <int, ORTCPClient>();
        StartListening();

        Observable
        .EveryUpdate()
        .Where(_ => _newConnections.Count > 0)
        .Subscribe(_ =>
        {
            //Debug.Log(Thread.CurrentThread.ManagedThreadId);
            NewConnection newConnection = _newConnections.Dequeue();
            ORTCPClient client          = ORTCPClient.CreateInstance("ORMultiServerClient", newConnection.tcpClient, this);


            int clientID = SaveClient(client);
            ORTCPEventParams eventParams = new ORTCPEventParams();
            eventParams.eventType        = ORTCPEventType.Connected;
            eventParams.client           = client;
            eventParams.clientID         = clientID;
            eventParams.socket           = newConnection.tcpClient;
            if (verbose)
            {
                print("[TCPServer] New client connected");
            }
        });
    }