Ejemplo n.º 1
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
                throw new InvalidOperationException("Server already bound, please use Unbind first");

            var ipAddress = IpAddressFromHostTranslator.GetIpAddressForHost(endpoint.Host);

            _endpoint = endpoint;

            _listener = new TcpListener(ipAddress, endpoint.Port);

            if (onClientConnected != null)
                ClientConnected += onClientConnected;
            if (onClientDisconnected != null)
                ClientDisconnected += onClientDisconnected;

            _stopped.Reset();
            _started.Reset();

            _listener.Start();

            _cts = new CancellationTokenSource();

            StartAcceptLoop(socketConfiguration, _cts.Token, nodeType);
        }
Ejemplo n.º 2
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
            {
                throw new InvalidOperationException("Server already bound, please use Unbind first");
            }

            var ipAddress = IpAddressFromHostTranslator.GetIpAddressForHost(endpoint.Host);

            _endpoint = endpoint;

            _listener = new TcpListener(ipAddress, endpoint.Port);

            if (onClientConnected != null)
            {
                ClientConnected += onClientConnected;
            }
            if (onClientDisconnected != null)
            {
                ClientDisconnected += onClientDisconnected;
            }

            _stopped.Reset();
            _started.Reset();

            _listener.Start();

            _cts = new CancellationTokenSource();

            StartAcceptLoop(socketConfiguration, _cts.Token, nodeType);
        }
Ejemplo n.º 3
0
        public ISocketAccepter CreateAndBind(RedFoxEndpoint endpoint,
            NodeType nodeType,
            ISocketConfiguration socketConfiguration,
            ClientConnectedDelegate onClientConnected = null,
            ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (socketConfiguration == null) throw new ArgumentNullException("socketConfiguration");

            var server = CreateForTransport(endpoint.Transport);
            server.Bind(endpoint, nodeType, socketConfiguration, onClientConnected, onClientDisconnected);
            return server;
        }
Ejemplo n.º 4
0
        public ISocketAccepter CreateAndBind(RedFoxEndpoint endpoint,
                                             NodeType nodeType,
                                             ISocketConfiguration socketConfiguration,
                                             ClientConnectedDelegate onClientConnected       = null,
                                             ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (socketConfiguration == null)
            {
                throw new ArgumentNullException("socketConfiguration");
            }

            var server = CreateForTransport(endpoint.Transport);

            server.Bind(endpoint, nodeType, socketConfiguration, onClientConnected, onClientDisconnected);
            return(server);
        }
Ejemplo n.º 5
0
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
                throw new InvalidOperationException("Server already bound, please use Unbind first");

            _listener = InProcessEndpoints.Instance.RegisterAccepter(endpoint);
            _endpoint = endpoint;

            if (onClientConnected != null)
                ClientConnected += onClientConnected;
            if (onClientDisconnected != null)
                ClientDisconnected += onClientDisconnected;

            _started.Reset();
            _cts = new CancellationTokenSource();
            Task.Factory.StartNew(() => StartAcceptLoop(_cts.Token, socketConfiguration), TaskCreationOptions.LongRunning);
            _started.Wait();
        }
        public void Bind(RedFoxEndpoint endpoint, NodeType nodeType, ISocketConfiguration socketConfiguration, ClientConnectedDelegate onClientConnected = null, ClientDisconnectedDelegate onClientDisconnected = null)
        {
            if (_listener != null || !_stopped.IsSet)
            {
                throw new InvalidOperationException("Server already bound, please use Unbind first");
            }

            _listener = InProcessEndpoints.Instance.RegisterAccepter(endpoint);
            _endpoint = endpoint;

            if (onClientConnected != null)
            {
                ClientConnected += onClientConnected;
            }
            if (onClientDisconnected != null)
            {
                ClientDisconnected += onClientDisconnected;
            }

            _started.Reset();
            _cts = new CancellationTokenSource();
            Task.Factory.StartNew(() => StartAcceptLoop(_cts.Token, socketConfiguration), TaskCreationOptions.LongRunning);
            _started.Wait();
        }
Ejemplo n.º 7
0
 public void UnsubscribeFromOnClientDisconnected(ClientDisconnectedDelegate _func)
 {
     m_onClientDisconnected -= _func;
 }
Ejemplo n.º 8
0
 public void SubscribeToOnClientDisconnected(ClientDisconnectedDelegate _func)
 {
     m_onClientDisconnected -= _func;
     m_onClientDisconnected += _func;
 }