BanyRule

display.py

Nov 25th, 2016
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import socket
  5. import json
  6.  
  7. HOST = ''
  8. PORT = 9090
  9.  
  10. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  11.     s.bind((HOST, PORT))
  12.     s.listen(4)
  13.  
  14.     client, addr = s.accept()
  15.  
  16.     with client:
  17.         print('connected:', addr)
  18.         while True:
  19.             try:
  20.                 data = client.recv(16384)
  21.                 if not data: continue
  22.             except ConnectionResetError:
  23.                 print('connection lost')
  24.                 break
  25.  
  26.             # декодированные данные
  27.             decoded_array = json.loads(data.decode('utf-8'))
  28.             print(decoded_array)
  29.  
  30.  
  31. client.close()
Add Comment
Please, Sign In to add comment