Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- import json
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- server_address=('localhost',10000)
- print >>sys.stderr,'Connectiong to port %s port %s' % server_address
- sock.connect(server_address)
- json_string='{"port":"12", "state":"HIGH"}'
- p_json=json.dumps(json_string).encode('utf-8')
- try:
- message = 'This is the msj. It willll be repeaded'
- print>>sys.stderr, 'sending "%s"' % message
- sock.sendall(p_json)
- amount_received = 0
- amount_expected = len(json_string)
- while amount_received < amount_expected:
- data=sock.recv(16)
- amount_received+=len(data)
- print>>sys.stderr, 'received "%s"' % data
- finally:
- print >sys.stderr,'Closing socket'
- sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement