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);
        }
Exemple #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);
        }
        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;
        }
Exemple #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);
        }
        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();
        }
Exemple #7
0
 public void UnsubscribeFromOnClientDisconnected(ClientDisconnectedDelegate _func)
 {
     m_onClientDisconnected -= _func;
 }
Exemple #8
0
 public void SubscribeToOnClientDisconnected(ClientDisconnectedDelegate _func)
 {
     m_onClientDisconnected -= _func;
     m_onClientDisconnected += _func;
 }