Advertisement
alexarcan

MS_client

Mar 26th, 2016
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. import socket
  2. import sys
  3. import json
  4.  
  5. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  6. server_address=('localhost',10000)
  7. print >>sys.stderr,'Connectiong to port %s port %s' % server_address
  8. sock.connect(server_address)
  9.  
  10. json_string='{"port":"12", "state":"HIGH"}'
  11. p_json=json.dumps(json_string).encode('utf-8')
  12.  
  13. try:
  14.     message = 'This is the msj. It willll be repeaded'
  15.     print>>sys.stderr, 'sending "%s"' % message
  16.     sock.sendall(p_json)
  17.    
  18.     amount_received = 0
  19.     amount_expected = len(json_string)
  20.    
  21.     while amount_received < amount_expected:
  22.         data=sock.recv(16)
  23.         amount_received+=len(data)
  24.         print>>sys.stderr, 'received "%s"' % data
  25.  
  26. finally:
  27.     print >sys.stderr,'Closing socket'
  28.     sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement