Ejemplo n.º 1
0
 private void handleTell(KQMLMessage msg, AbstractSimpleSocket socket)
 {
     receivedMsgs.Add(msg); // is this really necessary?
     Console.WriteLine($"[SocketStringConsumer] Received tell message: {msg.ToString()}");
     //socket.Send(KQMLMessage.createTell(this.name, msg.sender, this.nextMsgId(), msg.reply_with, ":ok").ToString());
     //this.Out.Post(msg.content.ToString(), DateTime.Now); // utilize... later
 }
Ejemplo n.º 2
0
 protected override void Receive(string message, Envelope e)
 {
     //Console.WriteLine($"[SocketStringConsumer] Consuming: {message}");
     if (ready && message.Length > 5)
     {
         var kqml = KQMLMessage.createAchieve(name, this.default_achieve_destination, nextMsgId(), null, $"(task :action (processKioskUtterance \"{message}\"))");
         //facilitator = new SimpleSocket(this.facilitatorIp, facilitatorPort);
         //facilitator.OnMessage = this.ProcessMessageFromUpstream;
         facilitator.Connect();
         Console.WriteLine($"[SocketStringConsumer] Sending: {kqml.ToString()}");
         facilitator.Send(kqml.ToString());
         //facilitator.Close();
     }
 }
Ejemplo n.º 3
0
        private void ProcessMessageFromUpstream(string data, AbstractSimpleSocket socket)
        {
            // push this into Out
            Console.WriteLine($"[SocketStringConsumer] Facilitator says: {data} - length {data.Length}");
            if (data.Length > 3)
            {
                KQMLMessage kqml = (new KQMLMessageParser()).parse(data);
                if (kqml != null && ready)
                {
                    switch (kqml.performative)
                    {
                    case "ping":
                    case "common-lisp-user::ping":
                        handlePing(kqml, socket);
                        break;

                    case "achieve":
                    case "common-lisp-user::achieve":
                        handleAchieve(kqml, socket);
                        break;

                    case "tell":
                    case "common-lisp-user::tell":
                        handleTell(kqml, socket);
                        break;

                    case "error":
                        Console.WriteLine($"[SocketStringConsumer] Error: {kqml.ToString()}");
                        break;

                    case "ask_all":
                    case "ask_one":
                    case "advertise":
                    case "untell":
                    case "subscribe":
                    default:
                        Console.WriteLine($"[SocketStringConsumer] Unknown KQML Performative: {kqml.performative}");
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine($"[SocketStringConsumer] Facilitator message ignored: {data}");
            }
        }
Ejemplo n.º 4
0
        private void ProcessMessageFromUpstream(string data, AbstractSimpleSocket socket)
        {
            KQMLMessage msg = (new KQMLMessageParser()).parse(data);

            socket.Send(KQMLMessage.createTell(msg.receiver, msg.sender, msg.reply_with, "echoer", ":ok").ToString());

            if (msg.performative != "tell" && msg.performative != "register")
            {
                Console.WriteLine($"[Echoer] Recieved data: {data}.");// ; Parsed content: {msg.content}");
                string temp = msg.receiver;
                msg.receiver = msg.sender;
                msg.sender   = temp;

                facilitator.Connect();
                var outbound_msg = msg.ToString();
                //Console.WriteLine($"[Echoer] Outbound message: {outbound_msg}");
                facilitator.Send(outbound_msg);
                facilitator.Close();
            }
        }
Ejemplo n.º 5
0
 public static KQMLMessage createAchieve(string sender, string receiver, string reply_with, string reply_to, KQMLMessage message)
 {
     return(new KQMLMessage("achieve", sender, receiver, reply_with, reply_to, message));
 }
Ejemplo n.º 6
0
 private void handleAchieve(KQMLMessage msg, AbstractSimpleSocket socket)
 {
     receivedMsgs.Add(msg); // is this really necessary?
     this.Out.Post(msg.content.ToString().Trim('"'), DateTime.Now);
     socket.Send(KQMLMessage.createTell(this.name, msg.sender, this.nextMsgId(), msg.reply_with, ":ok").ToString());
 }
Ejemplo n.º 7
0
        // performative handlers

        private void handlePing(KQMLMessage msg, AbstractSimpleSocket socket)
        {
            socket.Send($"(update :sender {this.name} :receiver facilitator :in-reply-to {msg.reply_with} :content (:agent psi :uptime 12h :state guess))");
        }