Created
July 24, 2018 15:41
-
-
Save a11ce/e6188b7a75d0f6837a0a402bfd3a83ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
HOST = 'unh.w1mem.com' | |
PORT = 25001 | |
def recPrint(s): | |
rec = s.recv(1024) | |
print(rec) | |
return(rec) | |
def main(): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
sock.connect((HOST, PORT)) | |
for _ in range(2): | |
recPrint(sock) | |
sock.send(b"one") | |
recPrint(sock) | |
count = 0 | |
while(True): | |
q = str(recPrint(sock)) | |
fw = str(q.split(" ")[0])) | |
if( fw == "b'And"): | |
print("un") | |
sock.send(str(count).encode()) | |
recPrint(sock) | |
recPrint(sock) | |
else: | |
count += 1 | |
op1 = int(q.split(" ")[7]) | |
op2 = int(q.split(" ")[9]) | |
res = int(q.split(" ")[11][:-1]) | |
if(op1 + op2 == res): | |
sock.send(b"add") | |
elif(op1 * op2 == res): | |
sock.send(b"mul") | |
elif(op1 - op2 == res): | |
sock.send(b"sub") | |
elif(op1 // op2 == res): | |
sock.send(b"div") | |
recPrint(sock) | |
sock.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment