need help in python lab report
Lab2 – CMET415 - Due Oct. 23, 2017 The internet applications are mostly made of two piece of codes, one runs in a client end-host and the other runs in a server end-host. Each host has an IP address and each application has a TCP port number. The end-hosts create sockets and communicate through these sockets. We described the following two codes during the class. The server side code must be run before the client side code so that it is ready to serve. In the following code server simply converts the message to upper case returns the upper case version of the message. Notice that message is received from a socket is encoded version therefore message.decode() converts it to normal string and then message.decode().upper() converts the string into upper case in the server side code. Please see the assignments after these two Python programs:
Client.py from socket import * server_name = 'localhost' server_port = 12003 client_socket = socket(AF_INET, SOCK_DGRAM) message = "Hello" client_socket.sendto(message.encode(), (server_name, server_port) ) modified_message, server_addr = client_socket.recvfrom(2048) print modified_message
Server.py from socket import * server_port = 12003 server_socket = socket(AF_INET, SOCK_DGRAM) server_socket.bind(('', server_port)) print 'The server is ready to receive' while True: message, client_addr = server_socket.recvfrom(2048) modified_message = message.decode().upper() server_socket.sendto(modified_message.encode(), client_addr)
P1. Type the above code and make them work by first running server.py and then the client.py which much print HELLO
P2. Modify the above two programs so that the client side sends a tuple of two integers such as (3, 8) and the server receives the tuple as the message and adds its entries 3+8 and then returns 11 back to the client. Client must print
the received message to the screen. In this case the client’s message will be (3, 8).
P3. Modify the above two programs so that the client side sends a tuple with multiple integer entries such as (4, 23, 5, 9) and the server receives this tuple as the message and adds its entries and returns the result back to the client.