Skip to content
Snippets Groups Projects
Commit 49aa3c46 authored by Doug Harms's avatar Doug Harms
Browse files

Modified threaded server for command line arguments

parent 2c9b50e1
No related merge requests found
......@@ -9,7 +9,7 @@ class serverThread( threading.Thread ):
threading.Thread.__init__(self)
self.connection = connection
self.clientAddress = clientAddress
# this method (which is automatically invoked by start) does all the processing for one client
def run(self):
print ('connection from {}'.format(self.clientAddress))
......@@ -25,13 +25,21 @@ class serverThread( threading.Thread ):
# Clean up the connection
self.connection.close()
# the main function
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# process command line arguments
argc = len(sys.argv)
if argc != 2:
print ("usage: python3 server.py serverPort")
sys.exit()
port = int(sys.argv[1])
# Bind the socket to the port
server_address = ('localhost', 10000)
server_address = ('',port)
print ('starting up on {} port {}'.format(server_address[0], server_address[1]))
sock.bind(server_address)
......@@ -46,5 +54,3 @@ while True:
# create a thread to handle this client
thread = serverThread( connection, client_address )
thread.start()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment