Пример #1
0
        private int SendMessage(string method, JObject payload, bool urgent = false)
        {
            int id = _runningId++;
            DemonicMessage message = new DemonicMessage();
            message.Id = id;
            message.Name = method;
            message.Payload = payload.ToString();
            message.Urgent = urgent;

            _outboundQueue.Enqueue(message);

            return id;
        }
Пример #2
0
        private void registerWithMaster(TcpClient tcp)
        {
            _log.log("Registering with Master");
            Stream stream = tcp.GetStream();

            StreamWriter sw = new StreamWriter(stream);

            DemonicMessage registerMessage = new DemonicMessage();
            registerMessage.Id = 1;
            registerMessage.Name = "register";
            registerMessage.Payload = new JObject(
                new JProperty("methods", "gethtml, test")
                ).ToString();

            Serializer.Serialize<DemonicMessage>(sw.BaseStream, registerMessage);
            StreamReader sr = new StreamReader(stream);
            DemonicMessage message = Serializer.Deserialize<DemonicMessage>(sr.BaseStream);
            sr.Close();
            if (message.Name.Equals("register"))
            {
                _masterEndpoint = new IPEndPoint(_masterAdress.Address, (int)JObject.Parse(message.Payload)["port"]);
            }

            _log.log("Registered, got " + _masterEndpoint.ToString());
            _toMaster = new TcpClient();
            _toMaster.Connect(_masterEndpoint);
            _toMaster.Client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, true);
            _toMasterStream = _toMaster.GetStream();
        }