Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- inputs = sys.argv
- HOST = inputs[len(inputs)-2]
- PORT = 27993
- if inputs[1] == "-p":
- PORT = int(inputs[2])
- nu_id = inputs[len(inputs)-1]
- with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
- s.connect((HOST, PORT))
- s.sendall(bytes("cs3700fall2019 HELLO " + nu_id + "\n", "ascii"))
- is_end = False
- while not is_end:
- msg = s.recv(8192)
- msg_decoded = msg.decode("ascii")
- split_msg = msg_decoded.split()
- key_word = split_msg[1]
- if key_word == "FIND":
- find_this = split_msg[2]
- blob = split_msg[3]
- total = blob.count(find_this)
- s.sendall(bytes("cs3700fall2019 COUNT " + str(total) + "\n", "ascii"))
- if key_word == "BYE":
- is_end = True
- print(split_msg[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement