Answered Essay: Design a protocol for exchanging messages between the client and the server. For simplicity, let's make each mes

Design a protocol for exchanging messages between the client and the server. For simplicity, let’s make each message one line, ending with the end-of-line character. Please, don’t use binary data, and limit the elements of the message to words, spaces, and printable characters. Please, describe the protocol in detail and use python language.

Expert Answer


# The below program are developed using TCP/IP protocol using sockets
# the server program opena socket in TCP/IP and make sure that, this server program should not be respond with the same master socket
# we will bind a 6000 port number to the socket.
# the listen function is capable of handling 5 client requests
# the server programs open a port number on its local address
# server wukk try to read the sockets from the client requests. This task will be accomplished by the accept.
# After listen, the server program will recevices the data
# the for loop will borad cast the message
#about client program
# the client program connects to the localaddress of the machine with the port number 6000
# recv method will receive the message from the server
# send method will send the data to the server program

import socket
import select

#Function to broadcast chat messages to all connected clients
def broadcast_data (sock, message):
for socket in CONNECTION_LIST:
if socket != server_socket and socket != sock :
try :
except :
# broken socket connection may be, chat client pressed ctrl+c for example

if __name__ == “__main__”:
# List to keep track of socket descriptors
RECV_BUFFER = 1024 # Advisable to keep it as an exponent of 2
PORT = 6000

server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((“”, PORT))

# Add server socket to the list of readable connections

print “Chat server started on port ” + str(PORT)

while 1:
# Get the list sockets which are ready to be read through select
read_sockets,write_sockets,error_sockets =,[],[])

for sock in read_sockets:
#New connection
if sock == server_socket:
# Handle the case in which there is a new connection recieved through server_socket
sockfd, addr = server_socket.accept()
print “Client (%s, %s) connected” % addr
broadcast_data(sockfd, “[%s:%s] entered roomn” % addr)
#Some incoming message from a client
# Data recieved from client, process it
#In Windows, sometimes when a TCP program closes abruptly,
# a “Connection reset by peer” exception will be thrown
data = sock.recv(RECV_BUFFER)
if data:
broadcast_data(sock, “r” + ‘<‘ + str(sock.getpeername()) + ‘> ‘ + data)
broadcast_data(sock, “Client (%s, %s) is offline” % addr)
print “Client (%s, %s) is offline” % addr

# Name the above program as
# run it as “python”

# client program

import socket, select, string, sys

def prompt() :
sys.stdout.write(‘<You> ‘)

#main function
if __name__ == “__main__”:

if(len(sys.argv) < 3) :
print ‘Usage : python hostname port’

hstname = sys.argv[1]
portnum = int(sys.argv[2])

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

# connect to remote host
try :
s.connect((hostname, portnum))
except :
print ‘Unable to connect to server’

print ‘Connected to server. Start sending messages’

while 1:
socket_list = [sys.stdin, s]

# Get the list sockets which are readable
read_sockets, write_sockets, error_sockets = , [], [])

for sock in read_sockets:
#incoming message from server
if sock == s:
data = sock.recv(1024)
if not data :
print ‘nDisconnected from the server’
else :
#print data
#user entered a message
else :
msg = sys.stdin.readline()

# Name the above program as
# run it as “python localhost 6000

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.


Let us write that nagging essay.


Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.


Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.


Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.


Receive your Paper

After Editing, your paper will be sent to you via email.