Advertisement
Guest User

Untitled

a guest
May 29th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import socket
  2.  
  3. HOST = ''  # Symbolic name, meaning all available interfaces
  4. PORT = 8888  # Arbitrary non-privileged port
  5.  
  6. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  8. s.bind((HOST, PORT))
  9.  
  10. # Start listening on socket
  11. s.listen(20)
  12.  
  13. total_sum = 20
  14.  
  15. # now keep talking with the client
  16. try:
  17.     while 1:
  18.         # wait to accept a connection - blocking call
  19.         conn, addr = s.accept()
  20.         r = conn.recv(1024)
  21.         t = 0
  22.         for i in r:
  23.             if i == ord('\n'):
  24.                 break
  25.             t += 1
  26.  
  27.         r = r[0:t]
  28.         print(r)
  29.         total_sum += int(r.decode("utf-8").split(": ")[1])
  30.         print(total_sum)
  31.         if total_sum < 0 or total_sum > 20:
  32.             print("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
  33.         conn.send(b"OK\n")
  34.         conn.close()
  35. except KeyboardInterrupt:
  36.     pass
  37. finally:
  38.     s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement