def testSend(self):
        dest, transactionid, msg = '/queue/myplace', '', '123 456 789'
        correct = "SEND\ndestination:%s\ncontent-type:text/plain\n\n%s\x00\n" % (dest, msg)
        result = stomper.send(dest, msg, transactionid)

        self.assertEquals(result, correct)

        dest, transactionid, msg = '/queue/myplace', '987', '123 456 789'
        correct = "SEND\ndestination:%s\ncontent-type:text/plain\ntransaction:%s\n\n%s\x00\n" % (dest, transactionid, msg)
        self.assertEquals(stomper.send(dest, msg, transactionid), correct)
Example #2
0
    def testSend(self):
        dest, transactionid, msg = '/queue/myplace', '', '123 456 789'
        correct = "SEND\ndestination:%s\ncontent-type:text/plain\n\n%s\x00\n" % (
            dest, msg)
        result = stomper.send(dest, msg, transactionid)

        self.assertEquals(result, correct)

        dest, transactionid, msg = '/queue/myplace', '987', '123 456 789'
        correct = "SEND\ndestination:%s\ncontent-type:text/plain\ntransaction:%s\n\n%s\x00\n" % (
            dest, transactionid, msg)
        self.assertEquals(stomper.send(dest, msg, transactionid), correct)
Example #3
0
 def send(self, routing_key, messages):
     """Convert a routing key and a list of messages into a STOMP frame."""
     f = stomper.Frame()
     f.unpack(stomper.send(routing_key, simplejson.dumps(messages)))
     f.headers["exchange"] = "wavelet.direct"
     f.headers["content-type"] = "application/json"
     return f.pack().encode("utf-8")
Example #4
0
	def send(self, routing_key, messages):
		"""Convert a routing key and a list of messages into a STOMP frame."""
		f = stomper.Frame()
		f.unpack(stomper.send(routing_key, simplejson.dumps(messages)))
		f.headers["exchange"] = "wavelet.direct"
		f.headers["content-type"] = "application/json"
		return f.pack().encode("utf-8")
Example #5
0
	def send(self, routing_key, message_data):
		"""Convert a routing_key and data dictionary into a STOMP message."""
		f = stomper.Frame()
		f.unpack(stomper.send(routing_key, anyjson.serialize(message_data)))
		f.headers["exchange"] = "wavelet.direct"
		f.headers["content-type"] = "application/json"
		return f.pack().encode("utf-8")
    def sendDataWithDataId(self,id, data):

        

        dataObject = {"sensorId": id,"data":data}
        threading.Timer(self.timeInterval, self.sendData).start()
        websocket.enableTrace(True)

          # Connecting to websocket
        ws = websocket.create_connection("ws://websocketapi-env.eba-gxghbmt3.us-east-1.elasticbeanstalk.com//sensor-data")

          # Subscribing to topic
        client_id = str(random.randint(0, 1000))
        sub = stomper.subscribe("/topic/collect", client_id, ack='auto')
        ws.send(sub)

          # Sending some message
          #print(dataObject)
        ws.send(stomper.send("/app/API/data", dataObject))

        while True:
            print("Receiving data: ")
            d = ws.recv()
            print(d)
            return
Example #7
0
    def testSend(self):
        dest, transactionid, msg = '/queue/myplace', '', '123 456 789'
        correct = "SEND\ndestination: %s\n\n%s\n%s\x00\n" % (dest, '', msg)
        result = stomper.send(dest, msg, transactionid)

#        print "result: "
#        pprint.pprint(result)
#        print
#        print "correct: "
#        pprint.pprint(correct)
#        print

        self.assertEquals(result, correct)

        dest, transactionid, msg = '/queue/myplace', '987', '123 456 789'
        correct = "SEND\ndestination: %s\ntransaction: %s\n\n%s\x00\n" % (dest, transactionid, msg)
        self.assertEquals(stomper.send(dest, msg, transactionid), correct)
Example #8
0
 def send_message(self, topic, message):
     f = stomper.Frame()
     f.unpack(stomper.send(topic, message))
     if not self.proto:
         log.debug("Queueing stomp frame for later delivery")
         self._frames.append(f)
     else:
         self.proto.transport.write(f.pack())
Example #9
0
    def testSend(self):
        dest, transactionid, msg = '/queue/myplace', '', '123 456 789'
        correct = "SEND\ndestination: %s\n\n%s\n%s\x00\n" % (dest, '', msg)
        result = stomper.send(dest, msg, transactionid)

        #        print "result: "
        #        pprint.pprint(result)
        #        print
        #        print "correct: "
        #        pprint.pprint(correct)
        #        print

        self.assertEquals(result, correct)

        dest, transactionid, msg = '/queue/myplace', '987', '123 456 789'
        correct = "SEND\ndestination: %s\ntransaction: %s\n\n%s\x00\n" % (
            dest, transactionid, msg)
        self.assertEquals(stomper.send(dest, msg, transactionid), correct)
Example #10
0
 def run(self):
     print("Receive thread started")
     while self.sentinel:
         try:
             time.sleep(10)
             send_message = stomper.send("/app/rcclient",
                                         str(self.clientId))
             self.connector.ws.send(send_message)
         except WebSocketConnectionClosedException:
             self.sentinel = False
Example #11
0
    def send(self):
        global message
        if not message:
            return
        self.log.debug("MSG:({}) {}: {}".format(strftime("%H:%M:%S"),
                                                self.nickname,
                                                message))

        if message == "/CONNECT":
            f = stomper.Frame()
            f.unpack(stomper.send(DESTINATION,
                                  "{} just connected".format(self.nickname)))
            self.transport.write(f.pack())
        elif message[:3] == "/ME":
            f = stomper.Frame()
            f.unpack(stomper.send(DESTINATION,
                                  "{} {}".format(self.nickname, message[4:])))
            self.transport.write(f.pack())
        elif message == "/HISTORY":
            data = ">".join(self.buffer)
            for i in range(len(self.buffer), MEM + 1):
                data += "\n"
            os.system("clear")
            print "{}\n--------------------------".format(data)
        elif message == "/QUIT":
            f = stomper.Frame()
            f.unpack(stomper.send(DESTINATION,
                                  "{} just exited".format(self.nickname)))
            reactor.callLater(1, self.closeConnection)
            self.transport.write(f.pack())
        else:
            f = stomper.Frame()
            f.unpack(stomper.send(DESTINATION,
                                  "({}) {}: {}".format(strftime("%H:%M:%S"),
                                                       self.nickname,
                                                       message)))
            self.transport.write(f.pack())
        message = ""
Example #12
0
    def send(self):
        """Send out a hello message periodically.
        """
        self.log.info("Saying hello (%d)." % self.counter)

        f = stomper.Frame()
        f.unpack(stomper.send(DESTINATION, 'hello there (%d)' % self.counter))

        self.counter += 1

        # ActiveMQ specific headers:
        #
        #f.headers['persistent'] = 'true'

        self.transport.write(f.pack())
    def send(self):
        """Send out a hello message periodically.
        """
        self.log.info("Saying hello (%d)." % self.counter)

        f = stomper.Frame()
        f.unpack(stomper.send(DESTINATION, 'hello there (%d)' % self.counter))

        self.counter += 1        

        # ActiveMQ specific headers:
        #
        #f.headers['persistent'] = 'true'

        self.transport.write(f.pack())
    def send(self, msg):
        """Send out a hello message periodically.
        """
        self.log.info("Saying hello (%d)." % self.counter)

        f = stomper.Frame()
        f.unpack(stomper.send(self.channel, self.message))

        self.counter += 1

        # ActiveMQ specific headers:
        #
        #f.headers['persistent'] = 'true'

        self.transport.write(f.pack())

        self.transport.loseConnection()
Example #15
0
    def send(self):
        """Send out a hello message periodically.
        """
        counter = self.counter.next()
        
        self.log.info("senderID:%s Saying hello (%d)." % (self.senderID, counter))

        f = stomper.Frame()
        f.unpack(stomper.send(DESTINATION, '(%d) hello there from senderID:<%s>' % (
            counter, 
            self.senderID
        )))

        # ActiveMQ specific headers:
        #
        #f.headers['persistent'] = 'true'

        self.transport.write(f.pack())
Example #16
0
    async def respond_using_ws(command: DittoCommand, count, delay_in_sec, request_id, response_url):
        logging.info("Responding over url= %s; delay= %s ms", response_url, delay_in_sec)
        ws = create_connection(response_url)

        idx = str(random.randint(0, 1000))
        sub = stomper.subscribe("/data", idx, ack='auto')
        ws.send(sub)
        for i in range(count):
            post_data = MeasurementData(request_id, count, i)
            time.sleep(delay_in_sec)
            msg = stomper.send(dest="/app/data", msg=post_data.to_json(), content_type="application/json")
            logging.debug("Going to send stomp message: %s", msg)
            ws.send(msg)
            # ws.send("some trash")
            # await ws.send(post_data.to_json())
            # await ws.recv()

        ws.send(stomper.unsubscribe(idx))
Example #17
0
    def handle_message(self, msg, **kwargs):
        init_time = kwargs.get('init_time', time.time())

        if "CONNECTED" in msg:
            logging.info("%s: Connection initiated", self.instanceId)
            request_success.fire(request_type='WebSocket Init',
                                 name='Init websocket connection',
                                 response_time=(time.time() - init_time) *
                                 1000,
                                 response_length=len(msg))
        elif "ERROR" in msg:
            logging.warning("%s: Received error: \n %s", self.instanceId,
                            str(msg))
            request_failure.fire(request_type='WebSocket Error',
                                 name='Websocket server Error',
                                 response_time=(time.time() - init_time) *
                                 1000,
                                 response_length=len(msg),
                                 exception=InterruptTaskSet())
            raise StopLocust()
        elif "MESSAGE" in msg:
            logging.info("%s: Message received: %s", self.instanceId, str(msg))
            message = str(msg)
            idx = message.find("{")
            content = message[idx:-1]

            json_msg = json.loads(content)
            res = stomper.send(
                "/app/device",
                '{ "time": "' + datetime.datetime.now().isoformat() + '",' +
                '"status": "OK",' + '"id": "' + json_msg["id"] + '",' +
                '"data": ' + str([1, 0, -1, 0]) + '}',
                content_type="application/json")
            self.ws.send(res)
            request_success.fire(request_type='Msg Receive',
                                 name='Msg received',
                                 response_time=(time.time() - init_time) *
                                 1000,
                                 response_length=len(msg))
Example #18
0
    def connect(self, clientId):
        try:
            self.ws = create_connection(self.rcServerUri)
            self.receiver = ReceiveThread(self)
            self.receiver.start()

            self.ws.send("CONNECT\naccept-version:1.0,1.1,2.0\n\n\x00\n")
            sub = stomper.subscribe("/user/rc/client-ack",
                                    clientId,
                                    ack='auto')
            self.ws.send(sub)
            sub = stomper.subscribe("/rc/" + str(clientId) + "/replayposition",
                                    clientId,
                                    ack='auto')
            self.ws.send(sub)

            send_message = stomper.send("/app/rcclient", str(clientId))
            self.ws.send(send_message)

            self.heartbeat = HeartbeatThread(self, clientId)
            self.heartbeat.start()
        except Exception as e:
            self.frame.SetStatusText(self.rcServerUri + ': ' + str(e), 2)
 def set_present(id_):
     ws = create_connection(config.get('websocket-endpoint'))
     ws.send(ANConnector.WS_HEADER)
     msg = stomper.send('/app/set-present', id_)
     ws.send(msg)
Example #20
0
 def send(self, msg, mq):
     f = stomper.Frame()
     f.unpack(stomper.send(mq, msg))
     self.counter += 1
     self.transport.write(f.pack())
Example #21
0
#!/usr/bin/env python


import stomper

ch = stomper.connect("", "", "172.17.5.194")

stomper.send(ch, "hello")

print ch
Example #22
0
 def send(self,dest, msg, transactionid=None, content_type='text/plain'):
     cmd = stomper.send(dest, msg, transactionid, content_type)  
     self._send(cmd)
Example #23
0
 def send(self, msg, mq):
     f = stomper.Frame()
     f.unpack(stomper.send(mq, msg))
     self.counter += 1        
     self.transport.write(f.pack())
Example #24
0
    # 초음파
    GPIO.setmode(GPIO.BCM)

    trig = 2
    echo = 3

    GPIO.setup(trig, GPIO.OUT)
    GPIO.setup(echo, GPIO.IN)

    while True:
        distance = sensor()

        if distance < 20:
            print("RUN SENSOR")
            ws.send(stomper.send(f"/socket/{hash_ip}/send", "ready"))
            time.sleep(5)
            user_id = int(getOrder(hash_ip)[7:])
            print(user_id)
            # 로그인이 안돼있을 때
            if not user_id:
                # TTS.main("안녕하세요 어르신! 성함을 말씀해 주세요!")
                tts = multiprocessing.Process(
                    target=TTS.main, args=("안녕하세요 어르신! 성함을 말씀해 주세요!", ))
                tts.start()
                message = STT.run()
                ws.send(stomper.send(f"/socket/{hash_ip}/send", message))
                user_id = int(getOrder(hash_ip)[7:])
                tts.terminate()

            # 로그인 돼있고, 메인화면 들어왔을 때
Example #25
0
        
        # Generate the ack or not if you subscribed with ack='auto'
        return super(Pong, self).ack(msg)
        

responder2 = Pong()
response = responder2.react(server_msg)
print("response:\n%s\n" % pprint.pformat(response))
#>>> 'ACK\nmessage-id: some-message-id\n\n\x00\n'


# We might want to send a message at some point. We could do this
# in two ways

# 1. using the the function for send()
send_message = stomper.send(DESTINATION, 'hello there') 
print("1. send_message:\n%s\n" % pprint.pformat(send_message))

#>>> 'SEND\ndestination: /queue/inbox\n\nhello there\x00\n'


# 2. using the frame class to add extra custom headers:
msg = stomper.Frame()
msg.cmd = 'SEND'
msg.headers = {'destination':'/queue/a','custom-header':'1234'}
msg.body = "hello queue a"
print("2. send_message:\n%s\n" % pprint.pformat(msg.pack()))

#>>> 'SEND\ncustom-header:1234\ndestination:/queue/a\n\nhello queue a\n\n\x00\n'

Example #26
0
def timer():
    time.sleep(35)
    ws.send(stomper.send(f"/socket/{hash_ip}/send", "그만"))
    global pose_close
    pose_close = True
    return