Draft a Python code to create datagram

Python Code to Create Datagarm.

import socket
UDP_IP = “localhost”
UDP_PORT = 5050
MESSAGE = "Hello UDP! "
print ("Sent Message: ", MESSAGE)
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.sendto(bytes(MESSAGE, “utf-8”), (UDP_IP, UDP_PORT))

Datagram is a type of wireless communication between two endpoints and it requires the ip address and port number to establish connection. Datagram uses UDP(User Datagram Protocol), it converts user data into small packets or chunks of data so that it can be sent over a network in a continuous manner. In UDP type of connection data packets have no records at the sender’s end, it just sends by the user then it’s upon receiver that it wants to accept data packets or not. UDP type of connection we use in video conferencing or in video calls.

import socket

UDP_IP = "localhost"
UDP_PORT = 8080
MESSAGE = "GeeksforGeeks"

print (“message:”, MESSAGE)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(bytes(MESSAGE, “utf-8”), (UDP_IP, UDP_PORT))