CS 351 TCP server python code assignment

Anonymous
timer Asked: Feb 18th, 2019
account_balance_wallet $15

Question Description

see the attachment see the attachment see the attachment

Modify the TCP server python code posted above as the following: 1- Find digits in a message received in the TCP server posted above. 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 2- If the client sends “exit”, the connection between the client and server is terminated, and the server prints "goody bye". – 20 points Note: we using Ubuntu terminal • • To run the python programs, type "python p2_tcp_server.py" on a terminal and "python p2_tcp_client.py 0.0.0.0" on another terminal. * Please submit your p2_tcp_server.py. You do not need to modify p2_tcp_client.py * # 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\n' % sock.getsockname()) sock.listen(1) while True: sys.stderr.write('waiting for a connection\n') connection, client_address = sock.accept() try: print 'client connected: address ', client_address while True: data = connection.recv(16) sys.stderr.write('received "%s"\n' % data.decode()) if data: # Find digits in data connection.sendall(data) else: break finally: connection.close() ______________________________________________________________________________ # 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\n' % server_address) sock.connect(server_address) while True: try: message = sys.stdin.readline().replace('\n','') sys.stderr.write('sending %s\n' % 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"\n' % data.decode()) except: sock.close() break

Tutor Answer

norrye
School: Purdue University

Here is the ...

flag Report DMCA
Review

Anonymous
Top quality work from this guy! I'll be back!

Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors