Question

Please take the following python server source code and add commenting and good programming practice updates:...

Please take the following python server source code and add commenting and good programming practice updates:

from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind((’’, serverPort))
print(”The server is ready to receive”)
while True:
message, clientAddress = serverSocket.recvfrom(2048)

modifiedMessage = message.decode().upper()

serverSocket.sendto(modifiedMessage.encode(), clientAddress)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Comments in python starts with "#" character. The entire line is considered to the a comment.

Note : We should always give an indentation after if, while and for loops. Since, you didn't mention any, I'm assuming all the statements written after while statement are part of while loop.

# Importing the required libraries i.e., socket

from socket import *

# Reserving an open port 12000 to serverPort so that it accepts the incoming request
serverPort = 12000

# Creating an instance of Socket and assigned two variables to it, AF_INET and SOCK_DGRM

# AF_INET represents address of IPV4 family

#SOCK_DGRM corresponds to connection oriented protocol
serverSocket = socket(AF_INET, SOCK_DGRAM)

# Binding the port

# passing an empty string instead of the IP

# Enables our computer to listen to any incoming requests from other computers on network
serverSocket.bind((’’, serverPort))

# Print statement to let user know that our socket is ready
print(”The server is ready to receive”)

# This is an infinite loop which runs till it is interrupted or an error occurs
while True:

# Configuring our computer to receive from Client address 2048
message, clientAddress = serverSocket.recvfrom(2048)

#Decoding the received message and coverting it into upper case

# Decoded message is stored in variable modifiedMessage

modifiedMessage = message.decode().upper()

# This modified message is now transferred to clientaddress

serverSocket.sendto(modifiedMessage.encode(), clientAddress)

Add a comment
Know the answer?
Add Answer to:
Please take the following python server source code and add commenting and good programming practice updates:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT