コード例 #1
0
        public void Run()
        {
            IsRunning = true;

            using (var socket = new ResponseSocket())
            {
                socket.Options.Linger = TimeSpan.Zero;

                socket.Bind(serverAddress.ZmqAddress + ":" + GlobalConstants.TcpIpPort.Request);

                while (!stopRunning)
                {
                    var request = socket.ReceiveNetworkMsg(TimeSpan.FromSeconds(1));

                    if (request == null)
                    {
                        continue;
                    }

                    var typedRequest = Converter.ChangeTo(request, request.GetType());                                  // TODO: ist noch unschön

                    var responseHandler = responseHandlerFactory.GetHandler(typedRequest, socket);
                    responseHandler.Handle(typedRequest);
                }
            }

            IsRunning = false;
        }
コード例 #2
0
        public void Run()
        {
            IsRunning = true;

            try
            {
                using (var socket = new ResponseSocket())
                {
                    socket.Options.Linger = TimeSpan.Zero;

                    socket.Bind(clientAddress.ZmqAddress + ":" + GlobalConstants.TcpIpPort.Heartbeat);

                    var timoutCounter = 0;

                    while (!stopRunning)
                    {
                        var request = socket.ReceiveNetworkMsg(TimeSpan.FromSeconds(1));

                        if (request == null)
                        {
                            timoutCounter++;

                            if (timoutCounter == 10)
                            {
                                Application.Current?.Dispatcher.Invoke(() => ServerVanished?.Invoke());
                                break;
                            }
                        }
                        else if (request.Type == NetworkMessageType.HeartbeatRequest)
                        {
                            timoutCounter = 0;
                            var heartbeatRequest = (HeartbeatRequest)request;
                            socket.SendNetworkMsg(new HeartbeatResponse(heartbeatRequest.SessionId));
                        }
                    }
                }
            }
            catch
            {
                // Ignored
            }

            IsRunning = false;
        }