Created
April 10, 2016 17:35
-
-
Save ksahnine/040965b53bf45b36448523d792723b9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
# Peudo code | |
def notify(tcpHost, tcpPort, device, logger): | |
# Create a socket (SOCK_STREAM means a TCP socket) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
data = json.dumps(device) | |
try: | |
# Connect to TCP server and send data | |
sock.connect((tcpHost, tcpPort)) | |
sock.send(data) | |
except socket.error: | |
logger.log(logging.ERROR, "Unable to connect to %s:%s. Please check your Node RED flow." % (tcpHost, tcpPort)) | |
finally: | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment