Question

I need some help in creating a pair of programs in Python UDPClient and UDPServer, that...

I need some help in creating a pair of programs in Python UDPClient and UDPServer, that use the UDP protocol to communicate with each other.

Once the sockets are set up, the communication will go as follows:

  1. The client reads a line of characters (data) from its keyboard and sends the data to the server.
  2. The server receives the data and converts the characters to uppercase.
  3. The server sends the modified data to the client.
  4. The client receives the modified data and displays the line on its screen.

The code should have UDP_IP & UDP_Port
Testing: will be executing both programs on separate consoles. Use "localhost" as the serverName on UDPClient. Run UDPServer on one console. Then run UDPClient on another console.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

UDP SERVER:

import socket

UDP_IP = "localhost"

UDP_PORT = 6780

serverSock = socket.socket()

serverSock.bind((UDP_IP, UDP_PORT))

serverSock.listen(5)

conn, addr = serverSock.accept()

data = conn.recv(UDP_PORT).decode()

new_data = data.upper()

conn.send(new_data.encode())

serverSock.close()

UDP CLIENT:

import socket

UDP_IP = "localhost"

UDP_PORT = 6780

message = input("Enter String: ")

clientSock = socket.socket()

clientSock.connect((UDP_IP, UDP_PORT))

clientSock.send(message.encode())

data = clientSock.recv(UDP_PORT).decode()

print(data)

clientSock.close()

Explanation:

socket.bind((UDP_IP, UDP_PORT)) will bind the ip address and port no to the socket.

socket.listen(n) will listen n requests and hold them in a queue, and drop the other requests after it.

conn.send(bytes) will take bytes like object and send it to bound address.

conn.recv(port_no) will take port_no as arg and return bytes like object

The data is sent from client to server, the server converts the string to a capital case and retransmits it back to the client.

str.encode() - (string to bytes)

bytes.decode() - (bytes to string)

These operations are required for proper communication.

Add a comment
Know the answer?
Add Answer to:
I need some help in creating a pair of programs in Python UDPClient and UDPServer, that...
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
  • Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or...

    Implement your first Networking application that uses the Client-Server model. Using Python and either TCP or UDP Protocol, the application should do the following: 1. Client reads a line of characters (data) from its keyboard and sends data to server 2. Server receives the data and converts characters to uppercase 3. Server sends modified data to client 4. Client receives modified data and displays line on its screen

  • In Python, make changes in the client code, so that the client allows the user to...

    In Python, make changes in the client code, so that the client allows the user to continue to send multiple requests until the user types in “Quit”. This means that the client process should not exit after the user sends one request and receives one response. Instead, the client process should be able to receive subsequent inputs from the user. You need to have a loop in the client code, so that it can accept the user request until the...

  • *****Can someone please HELP me with this assignment please, I am struggling with this assignment and...

    *****Can someone please HELP me with this assignment please, I am struggling with this assignment and would appreciate some help, needs to be done in c/c++ ******* (100 marks) In this problem, you will write a file transfer program for transferring files between two computers connected by a network. The protocol that you will implement is called the Simple File Transfer Protocol (SFTP). The complete description for SFTP is given below. PART 1 SFTP is a simple protocol for transferring...

  • Write two programs Client and Server

    Given two integer matrices A and B, you are requested to compose a program to perform matrix addition (A + B). Both matrices have N rows and M columns; N > 1, M > 1; You need to divide both (A and B) into four equal (or close to equal) size of submatrices (A0,0, A0,1, A1,0, A1,1 and B0,0, B0,1, B1.0, B1.1)andeachsubmatrixhasdimensioncloseto(N/2)x(M/2). YouneedtocreatefourJavathreads each thread performs a subset of addition on one pair of the submatrices. Example, thread 0 performs addition...

  • I need help with this questions on creating a chart like the one shown below please...

    I need help with this questions on creating a chart like the one shown below please Good Buy, Inc. (a fictitious company) sells a variety of consumer pro- ducts through its Web site, good-buy.com. Good Buy's IT infrastructure consists of a front-end Web server that interacts with customers and a back-end ERP system that manages the inventory and performs other typical ERP functions. The sales order process begins when a customer logs on to the good-buy.com Web site. The customer...

  • i need help with this python assignment asking for creating a simple database (client application )...

    i need help with this python assignment asking for creating a simple database (client application ) そ归乔 Assignment rh ENCS-393-2174-WW: Tset5.pdf A2.pdf textbook.pdf Department of ComputV ← → O仚 file:///C 18/comp%20348/A2.pdf 5. Print Report: This will print the contents of the database, sorted by name. Note that the sorted contents should be sent by the server back to the client and then displayed by the client app. The Print Report function is r because it is the primary way for...

  • This is in C. For this assignment we will write a simple database server. We will...

    This is in C. For this assignment we will write a simple database server. We will be creating a simple database of student records, so let’s describe these first. The format of a student record is as follows: typedef struct student {     char lname[ 10 ], initial, fname[ 10 ];     unsigned long SID;     float GPA; } SREC; Part One – the Server We will create a database server. The job of the server is to accept a...

  • I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration...

    I need help with this exercise. Than you for the help. Language is C++ 2 Enumeration Data Types Reformat is the shell of a program designed to read characters and process them in the following way Lowercase character Uppercase character Digit Blank Newline Any other character Converts to uppercase and writes the character Writes the character Writes the digit Writes a blank Writes newline Does nothing / Program Reformat reads characters from file DataIn and // writes them to DataOut...

  • For Python-3 I need help with First creating a text file named "items.txt" that has the...

    For Python-3 I need help with First creating a text file named "items.txt" that has the following data in this order: Potatoes Tomatoes Carrots. Write a python program that 1. Puts this as the first line... import os 2. Creates an empty list 3. Defines main() function that performs the tasks listed below when called. 4. Put these two lines at the top of the main function... if os.path.exists("costlist.txt"): os.remove("costlist.txt") Note: This removes the "costlist.txt" file, if it exists. 5....

  • 166 Chapter 8: TCP/IP Applications Getting Down to Business The way network communication all those ls...

    166 Chapter 8: TCP/IP Applications Getting Down to Business The way network communication all those ls and Os) goes in and out of a machine physically is through the NIC (network interface card). The way network communication goes in and out of a machine logically though, is through a program or service. A service is a program that runs in the background, independent of a logon, that provides functionalities to a system. Windows client machines, for instance, have a Workstation...

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
ADVERTISEMENT