The community forums are in BETA and closed to the public.

Low-level Embedded TCP Socket Streaming with PubNub using Python Example

Low-level Embedded TCP Socket Streaming with PubNub using Python Example

If you use Socket.IO or SignalR, you'll have an easy time getting setup with a JavaScript demo. However when it comes to lower-level communication it becomes more involved. Enter PubNub for an easy TCP Streaming solution for your low-level embedded devices. The follow solution example code is for those engineers who enjoy efficiency and also Python.

import socket

host = "ps.pubnub.com"
port = 80

s = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
s.connect(( socket.gethostbyname(host), port ))
s.send('GET /stream/demo/bot/0/-1 HTTP/1.1\r\nHost: %s\r\n\r\n' % host)

while True: print(s.recv(32))

And to gather some of the additional features such as PAM and Presence, you can append two params to the CALL such as authkey=abcd and uuid=abcd. The authkey is for PAM read/write permissions on a per-channel basis. The uuid is for Presence Device/User ID.

PAM PubNub Access Manager to TCP Data Stream

s.send('GET /stream/demo/bot/0/-1?auth_key=abcd HTTP/1.1\r\nHost: %s\r\n\r\n' % host)

Adding Presence User/Device ID to TCP Data Stream

s.send('GET /stream/demo/bot/0/-1?auth_key=abcd&uuid=abcd123 HTTP/1.1\r\nHost: %s\r\n\r\n' % host)

Comments to this discussion are now closed!