Question
My assignment is to create a TCP server and client using python (**version 3.6.3**). How do I write the program in python with the following
My assignment is to create a TCP server and client using python (**version 3.6.3**). How do I write the program in python with the following instructions?
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
1. 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.
2. 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.
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 are templates of what our instructor provided:
tcp_client_starter.py
#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
#Establish a variable to hold the server address and port number
#Using the socket a connection is made to the server using the connect() function and our destination address
#Print a message for the user to respond to
#After a connection is established , we send messages input from the user using sendall() function
#Shuts down half of the connection - using SHUT_WR disallows any more sends
#Reset the variable to an empty string in preparation of receiving message back from server
#Start an infinite loop to send data back and forth
#Display the data received from the server using the recv() function, passing in the buffer size
#This function returns number of bytes received
#If nothing is received back from the socket, then break out of the loop
#Decode the data sent back and put in into our message variable
#Display the message echoed by the server
#Release the resources and mark the socket as closed
#Prompt user to quit
and
tcp_server_starter.py
#Write a TCP echo server
import socket
#In the TCP Echo server , we create a socket and bind to a advertized port number.
#Establish a variable to hold the server address and port number we are binding to
#Bind the socket to the address
#After binding , the process listens for incoming connections, listen() enables server to accept connections
#Then an infinite loop is started to process the client requests for connections.
#After a connection is requested , it accepts the connection from the client machine and forks a new process.
#Establish message variable
#Receive data until the client closes the connection
#The new process receives data from the client using recv()
function and echoes the same data using the send() function.
#If no data is sent back, then break out of the loop
#Decode the data sent back and put in into our message variable
#Convert to uppercase - just to change the message up a little
#Encode and send back the message to the client (echo the message)
#Close the forked process
#Release the resources and mark socket as closed
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