Question: I need assistance in finishing this assignment in python version 3.6.3 **please read carefully all of what I put within asterisks** The following is what
I need assistance in finishing this assignment in python version 3.6.3 **please read carefully all of what I put within asterisks**
The following is what my instructor has asked:
In this assignment you will create a TCP Server and Client. You will implement a TCP QOTD (Quote of the Day) Client and Server program similar to the UDP assignment. Submit your .py files on Canvas.
TCP QOTD Client and Server **The client program should:
1. Accept a host and port number from the command line or prompt the user for these values at startup.
2. Request the QOTD from the specified host and port over TCP.
3. Print out the resulting quote. **
**The server program should:
1. Accept a port number from the command line or prompt the user for this value at startup.
2. Accept connections from any address. You do not need to handle more than one connection at a time, however, once you have transferred the file you should go back to accepting connections.
3. Reply to requests with the QOTD. This can be a single hard-coded quote **i am fine with a hard-coded quote by the way if you want to do that**. **
To test your client, **try requesting the QOTD from djxmmx.net on port 17. To test your sever, try requesting the QOTD from your server using your client.** Because TCP is byte/stream oriented, you will want to consider how your program will handle the sending and receiving of information.
Will you use a fixed-size format for the request?
Will you specify the size of the request in the first several bytes of the message?
Will you use a delimiter to indicate the end of the request?
Will you close the connection after the request has been sent?
Similarly you need to decide the same thing for the response.
Will you use a fixed-size format for the response?
Will you specify the response size in the first several bytes of the message?
Will you use a delimiter to indicate the end of the response?
Will you close the connection after the response has been sent?
**The following is what our instructor has given us through a video as an example to get us started and what I kindly ask, is someone to help fill out the rest of the following code I provide that fulfills the 3 items for the client and the 3 items for the server that were mentioned earlier in the instructions**
For the client I have:
#Write a TCP echo client import socket
#In the TCP Echo client a socket is created. #Use socket.SOCK_STREAM for TCP - this is also the default sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#Establish a variable to hold the server address and port number dest_addr = ("localhost", 4567)
#Using the socket a connection is made to the server using the connect() function and our destination address sock.connect(dest_addr)
#Print a message for the user to respond to message = input("What do you want to say to the server?")
#After a connection is established , we send messages input from the user using sendall() function sock.sendall(message.encode('ascii'))
#Shuts down half of the connection - using SHUT_WR disallows any more sends sock.shutdown(socket.SHUT_WR)
#Reset the variable to an empty string in preparation of receiving message back from server message = '' #Start an infinite loop to send data back and forth while 1: #Display the data received from the server using the recv() function, passing in the buffer size #This function returns number of bytes received data = sock.recv(4056) #If nothing is received back from the socket, then break out of the loop if not data: break
#Decode the data sent back and put in into our message variable message += data.decode('ascii')
#Display the message echoed by the server print("Message:", message)
#Release the resources and mark the socket as closed sock.close()
#Prompt user to quit input("Press enter to quit:")
and for the Server I have:
#Write a TCP echo server import socket
#In the TCP Echo server , we create a socket and bind to a advertized port number. sock = socket.socket() #default to socket (socket.AF_INET, socket.Sock_STREAM)
#Establish a variable to hold the server address and port number we are binding to bound_addr = ('localhost', 4567)
#Bind the socket to the address sock.bind(bound_addr)
#After binding , the process listens for incoming connections, listen() enables server to accept connections sock.listen(5)
#Then an infinite loop is started to process the client requests for connections. while 1: #loop to accepting new connections #After a connection is requested , it accepts the connection from the client machine and forks a new process. new_sock, conn_addr = sock.accept()
#Establish message variable message = ''
#Receive data until the client closes the connection while 1:
#The new process receives data from the client using recv() function and echoes the same data using the send() function. data = new_sock.recv(4096)
#If no data is sent back, then break out of the loop if not data break
#Decode the data sent back and put in into our message variable message += data.decode('ascii')
#Convert to uppercase - just to change the message up a little response = message.upper()
#Encode and send back the message to the client (echo the message) new_sock.send(response.encode('ascii'))
#Close the forked process new_sock.close()
#Release the resources and mark socket as closed sock.close()
**again just to be clear, I am asking for someone to help me finish the code for each that will fulfill the 3 items for what the client should do and the 3 items for what the server should do. I appreciate your time and help with this**
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
