Question
Modify the TCP server python code posted below as the following: Find digits in a message received in the TCP server posted below. A TCP
Modify the TCP server python code posted below as the following:
- Find digits in a message received in the TCP server posted below. A TCP client must send the TCP server a message containing alpha-numeric characters (A-Z, 0-9). The server finds only numerical characters in the message and send the characters to the client. 80 points
- If the client sends exit, the connection between the client and server is terminated, and the server prints "goody bye". 20 points
# TCP Client Python code import socket import sys
# Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port on the server given by the caller server_address = (sys.argv[1], 10000) sys.stderr.write('connecting to %s port %s ' % server_address) sock.connect(server_address)
while True: try: message = sys.stdin.readline().replace(' ','') sys.stderr.write('sending %s ' % message) sock.sendall(message.encode())
if message.lower() == 'exit': sock.close() break
#amount_received = 0 #amount_expected = len(message) #while amount_received < amount_expected: data = sock.recv(16) amount_received = len(data.decode()) sys.stderr.write('received "%s" ' % data.decode())
except: sock.close() break
# TCP Server Python code import socket import sys
# Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the address given on the command line server_address = ('', 10000) sock.bind(server_address) sys.stderr.write('starting up on %s port %s ' % sock.getsockname()) sock.listen(1)
while True: sys.stderr.write('waiting for a connection ') connection, client_address = sock.accept() try: print 'client connected: address ', client_address while True: data = connection.recv(16) sys.stderr.write('received "%s" ' % data.decode()) if data: # Find digits in data connection.sendall(data) else: break finally: connection.close()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started