#!/usr/bin/env python3 from socket import * from struct import pack, unpack # Create a socket. This doesn't open a port or anything yet # Parameters: # AF_INET is ipv4, AF_INET6 # SOCK_STREAM means TCP, SOCK_DGRAM would be UDP our_socket = socket(AF_INET, SOCK_STREAM) our_socket.connect(("isoptera.lcsc.edu", 5111)) while True: problem = input("Enter an addition problem like 4 + 5: ") a, op, b = problem.split() if(op != '+'): print("Sorry, unsupported operand, goodbye!") break data_to_send = pack("!ii", int(a), int(b)) our_socket.send(data_to_send) packed_result = our_socket.recv(4) result = unpack("!i", packed_result) # To unpack the tuple unpack gave us print("The answer was: ", result[0]) our_socket.close()