Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. import socket
  2. import sys
  3.  
  4. inputs = sys.argv
  5.  
  6. HOST = inputs[len(inputs)-2]
  7. PORT = 27993
  8. if inputs[1] == "-p":
  9. PORT = int(inputs[2])
  10.  
  11. nu_id = inputs[len(inputs)-1]
  12.  
  13. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  14. s.connect((HOST, PORT))
  15. s.sendall(bytes("cs3700fall2019 HELLO " + nu_id + "\n", "ascii"))
  16.  
  17. is_end = False
  18. while not is_end:
  19. msg = s.recv(8192)
  20. msg_decoded = msg.decode("ascii")
  21. split_msg = msg_decoded.split()
  22. key_word = split_msg[1]
  23.  
  24. if key_word == "FIND":
  25. find_this = split_msg[2]
  26. blob = split_msg[3]
  27. total = blob.count(find_this)
  28.  
  29. s.sendall(bytes("cs3700fall2019 COUNT " + str(total) + "\n", "ascii"))
  30. if key_word == "BYE":
  31. is_end = True
  32. print(split_msg[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement