Esempio n. 1
0
        public void Setup()
        {
            ManualResetEvent mre = new ManualResetEvent(false);
            var cert             = new X509Certificate2(new SocketHelper().GetCertFileContents(), "Password");

            _server = new SimpleSocketTcpSslListener(cert);
            _client = new SimpleSocketTcpSslClient(cert);

            new Thread(() => _server.StartListening(13000)).Start();

            ClientConnectedDelegate con = (client) =>
            {
                _clientid = client.Id;
                mre.Set();
            };

            _contract = new MessageContractImpl();
            _client.AddMessageContract(_contract);
            _server.AddMessageContract(_contract);

            _server.ClientConnected += con;

            _client.StartClient("127.0.0.1", 13000);

            mre.WaitOne(10000);
            _server.ClientConnected -= con;
        }
Esempio n. 2
0
        public void Setup()
        {
            Counter          clientCounter = new Counter();
            ManualResetEvent mre           = new ManualResetEvent(false);

            _cert = new X509Certificate2(new SocketHelper().GetCertFileContents(), "Password");

            _server = new SimpleSocketTcpSslListener(_cert);

            new Thread(() => _server.StartListening(13000)).Start();

            ClientConnectedDelegate con = (client) =>
            {
                clientCounter.Count();
                if (clientCounter.GetCount == _numClients)
                {
                    mre.Set();
                }
            };


            _server.ClientConnected += con;

            for (var i = 0; i < _numClients; i++)
            {
                initClient();
            }


            mre.WaitOne(new TimeSpan(0, 20, 0));

            _server.ClientConnected -= con;

            Assert.AreEqual(_numClients, clientCounter.GetCount);
        }
Esempio n. 3
0
        public void Setup()
        {
            ManualResetEvent mre = new ManualResetEvent(false);

            _server = new SimpleSocketTcpListener();
            _client = new SimpleSocketTcpClient();

            new Thread(() => _server.StartListening(13000)).Start();

            ClientConnectedDelegate con = (client) =>
            {
                _clientid = client.Id;
                mre.Set();
            };

            _contract = new MessageContractImpl();
            _client.AddMessageContract(_contract);
            _server.AddMessageContract(_contract);

            _server.ClientConnected += con;

            _client.StartClient("127.0.0.1", 13000);

            mre.WaitOne(10000);
            _server.ClientConnected -= con;
        }
Esempio n. 4
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);
        }
Esempio 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");
            }

            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);
        }
Esempio n. 6
0
        public void Setup()
        {
            Counter          clientCounter = new Counter();
            ManualResetEvent mre           = new ManualResetEvent(false);

            _server = new SimpleSocketTcpListener();

            new Thread(() => _server.StartListening(13000)).Start();

            ClientConnectedDelegate con = (client) =>
            {
                clientCounter.Count();
                if (clientCounter.GetCount == _numClients)
                {
                    mre.Set();
                }
            };


            _server.ClientConnected += con;

            for (var i = 0; i < _numClients; i++)
            {
                initClient();
            }


            mre.WaitOne(new TimeSpan(0, 5, 0));

            _server.ClientConnected -= con;

            Assert.AreEqual(_numClients, clientCounter.GetCount);
        }
        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;
        }
Esempio n. 8
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();
        }
Esempio n. 10
0
        public void Connect(string appName, string appKey, string appVersion)
        {
            messageQueue     = new List <string>();
            messageAvailable = new AutoResetEvent(false);

            IQFeed_CallBack = new ClientConnectedDelegate(IQFeedAdapter.SetConnected);
            SetCallbackFunction(IQFeed_CallBack);

            RegisterClientApp(IntPtr.Zero, appName, appKey, appVersion);

            while (!isConnected)
            {
                Thread.Sleep(100);
            }

            try
            {
                client              = new TcpClient(ServerAddress, ServerPort);
                messageStream       = client.GetStream();
                messageStreamReader = new StreamReader(messageStream);

                string keyData = ReadStream(messageStreamReader);
                keyData = keyData.Split('\n')[0] + "\n";
                WriteStream(messageStream, keyData);
                keyData = ReadStream(messageStreamReader);

                monitoringActive = true;
                messageThread    = new Thread(new ThreadStart(ReceiveMessages));
                eventThread      = new Thread(new ThreadStart(ConsumeMessages));

                messageThread.Start();
                eventThread.Start();
            }
            catch (ArgumentNullException e)
            {
                throw e;
            }

            catch (SocketException e)
            {
                throw e;
            }
        }
        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();
        }
Esempio n. 12
0
 public void UnsubscribeFromOnClientConnected(ClientConnectedDelegate _func)
 {
     m_onClientConnected -= _func;
 }
Esempio n. 13
0
 public void SubscribeToOnClientConnected(ClientConnectedDelegate _func)
 {
     m_onClientConnected -= _func;
     m_onClientConnected += _func;
 }
Esempio n. 14
0
 private static extern void SetCallbackFunction(ClientConnectedDelegate SetConnected);