Exemplo n.º 1
0
 public Kernel(ConnInfo conn, ILoggerFactory loggerFactory)
 {
     _conn = conn;
     // https://netmq.readthedocs.io/en/latest/router-dealer/
     _shellAddress  = $"@tcp://{conn.IP}:{conn.ShellPort}";
     _iopubAddress  = $"@tcp://{conn.IP}:{conn.IOPubPort}";
     _loggerFactory = loggerFactory;
 }
Exemplo n.º 2
0
        public Kernel(ConnInfo conn)
        {
            var exit = false;

            // catch CTRL+C as exit command
            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                exit     = true;
            };

            // https://netmq.readthedocs.io/en/latest/router-dealer/
            string serverAddress = $"@tcp://{conn.IP}:{conn.ShellPort}";
            string iopubAddress  = $"@tcp://{conn.IP}:{conn.IOPubPort}";

            using (var server = new RouterSocket(serverAddress))
                using (var iopub = new PublisherSocket(iopubAddress))
                    using (var poller = new NetMQPoller())
                    {
                        var sender = new MessageSender(conn.Key, iopub);

                        // Handler for messages coming in to the frontend
                        server.ReceiveReady += (s, e) =>
                        {
                            var raw = e.Socket.ReceiveMultipartMessage();
                            Console.WriteLine($"Received: {raw.ToString()}");
                            var header = JsonConvert.DeserializeObject <Header>(raw[3].ConvertToString());

                            switch (header.MessageType)
                            {
                            case "kernel_info_request":
                                new KernelInfoHandler <ContentOfKernelInfoRequest>(sender)
                                .Process(new Message <ContentOfKernelInfoRequest>(header, raw));
                                break;

                            case "execute_request":
                                new ExecuteHandler <ContentOfExecuteRequest>(sender)
                                .Process(new Message <ContentOfExecuteRequest>(header, raw));
                                break;
                            }
                        };

                        poller.Add(server);
                        poller.RunAsync();

                        // hit CRTL+C to stop the while loop
                        while (!exit)
                        {
                            Thread.Sleep(100);
                        }
                    }
        }
Exemplo n.º 3
0
        public HeartBeat(ConnInfo conn)
        {
            string heartbeatAddress = $"@tcp://{conn.IP}:{conn.HBPort}";

            using (var responseSocket = new ResponseSocket(heartbeatAddress))
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        var message = responseSocket.ReceiveFrameString();

                        Console.WriteLine("ResponseSocket : Server Received '{0}'", message);

                        responseSocket.SendFrame("OK");
                        Console.WriteLine("Response OK.");

                        Thread.Sleep(1000);
                    }
                });
            }
        }