Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

receiving messages from a TCP socket in Python #33

Open
eadmaster opened this issue Dec 28, 2017 · 2 comments
Open

receiving messages from a TCP socket in Python #33

eadmaster opened this issue Dec 28, 2017 · 2 comments

Comments

@eadmaster
Copy link

eadmaster commented Dec 28, 2017

Is it possible to receive the messages sent to a service via a TCP socket and a simple Python script?
I've tried using the script in this page + this code for subscription, but it didn't work (invalid UUID error):

#!/usr/bin/env python
from uuid import uuid4
from socket import socket, AF_INET, SOCK_STREAM
from json import loads as json_decode
import logging
import json

uuid   = uuid4()  # this device ID (random generated)
uuid = str(uuid).upper()
print("geneated uuid=" + str(uuid))
server = 'api.pushjet.io'
port   = 7171

import requests
r = requests.post('https://api.pushjet.io/subscription', params={ 'uuid': '\''+str(uuid)+'\'', 'service': MY_SERVICE_ID })
print(r.status_code)
if(r.status_code!=200):
    print("subscription error: " + str(r.status_code))
    exit (1)
else:
    print(str(r.json()))

print("Connecting as {} to {}:{}".format(uuid, server, port))
pj_sock = socket(AF_INET, SOCK_STREAM)
pj_sock.connect((server, port))
pj_sock.send(bytes(uuid))
... # the rest it's the same as the script here http://docs.pushjet.io/docs/tcp
@Mechazawa
Copy link
Member

r = requests.post('https://api.pushjet.io/subscription', params={ 'uuid': '\''+str(uuid)+'\'', 'service': MY_SERVICE_ID })

should most likely be

r = requests.post('https://api.pushjet.io/subscription', params={ 'uuid': +str(uuid), 'service': MY_SERVICE_ID })

From what I can infer from your code is that it sends the uuid with two single quotes (') on each side. Not just the uuid.

@eadmaster
Copy link
Author

eadmaster commented Jan 11, 2018

thank you for the tip, now it subscribes correctly, but after that it is not receiving the messages i sent via curl (while the android app is receiving them just fine)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants