Preview

Socket Programming for UDP in Python

Satisfactory Essays
Open Document
Open Document
540 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Socket Programming for UDP in Python
COMPUTER NETWORKS
SOCKET PROGRAMMING
LAB ASSIGNMENT : 5

Aim :- SOCKET PROGRAMMING : UDP
In this lab, you will learn the basics of socket programming for
UDP in Python. You will learn how to send and receive datagram packets using UDP sockets and also, how to set a proper socket timeout.
Throughout the lab, you will gain familiarity with a Ping application and its usefulness in computing statistics such as packet loss rate.
Server Code :The following code fully implements a ping server. You need to compile and run this code before running your client program :
#We will need the following module to generate randomized lost packets import random import socket from socket import *
#Create a UDP socket
# Notice the use of SOCK_DGRAM for UDP packets serverSocket = socket(AF_INET, SOCK_DGRAM)
# Assign IP address and port number to socket serverSocket.bind(('', 12555)) while True:

# Generate random number in the range of 0 to 10 rand = random.randint(0, 10)
# Receive the client packet along with the address it is coming from message, address = serverSocket.recvfrom(1024) print message
# Capitalize the message from the client message = message.upper()
#If rand is less is than 4, we consider the packet lost and do not respond if rand < 4: continue # Otherwise, the server responds serverSocket.sendto(message, address)

In this server code, 30% of the client’s packets are simulated to be lost.
The server sits in an infinite loop listening for incoming UDP packets. When a packet comes in and if a randomized integer is greater than or equal to 4, the server simply capitalizes the encapsulated data and sends it back to the client.

Client Code :The client should send 10 pings to the server. Because UDP is an unreliable protocol, a packet sent from the client to the server may be lost in the network, or vice versa . For this reason, the client can not wait indefinitely for a reply to a ping message. You should get the client wait up to one second for a reply; if no reply is

You May Also Find These Documents Helpful

  • Satisfactory Essays

    Week 5 6 ILAB SriLakshmi

    • 773 Words
    • 3 Pages

    According to the lab help files it contains random outcomes for the size of generated packets (specified in bytes)…

    • 773 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Unit 5 Lab JM

    • 625 Words
    • 5 Pages

    2. If not found build ARP request frame containing MAC address, IP Address, and forwarding IP address.…

    • 625 Words
    • 5 Pages
    Satisfactory Essays
  • Powerful Essays

    At the destination this layer is responsible for combining the packets into their original state. This layer also checks to see if the layers are in the right order when received and not in duplicated form. If there is an error in one of the packets there is a request for that packet's retransmission. There are two protocols that sit at this layer. First, the TCP protocol connects the sender and the receiver using a socket which is determined by the IP address and port number. TCP keeps track of the packet delivery order and which ones need to be resent. UDP on the other hand is a connectionless communication and does not guarantee packet delivery between sender and receiver. Because it is connectionless the sender sends the data into the network with an IP address of the receiver and hopes it makes it to its destination. Since there is not a way of asking the sender to retransmit because of an error there is little error protection if…

    • 1266 Words
    • 6 Pages
    Powerful Essays
  • Satisfactory Essays

    NT1210 Chapter 5.2.6

    • 342 Words
    • 2 Pages

    Step 4: The message is received by each device on the LAN since it is a broadcast. Each device compare the Target Protocol Address (IPv4 Address of the machine to which the source is trying to communicate) with its own Protocol Address (IPv4 Address). Those who do not match will drop the packet without any action.…

    • 342 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    Nt1330 Unit 5 Assignment 1

    • 1348 Words
    • 6 Pages

    4. The client accept the connection and send data to server and the server to replay the…

    • 1348 Words
    • 6 Pages
    Good Essays
  • Good Essays

    Nt1310 Unit 7 Gdp

    • 311 Words
    • 2 Pages

    There are a few problems I would anticipate with using this combination of protocols. The first is if there is some sort of failure with the delivery of the sequence of data packets. As UDP is connectionless there isn’t a reliable order that the packets will arrive, one would assume this is why they are using stop and wait, to try and compensate for this issue. As a result, you may get some packets timing out and being resent by the server causing duplicate packets to be sent, all while awaiting ACK arrival even though there may not have actually been any failure. Then there are extra packets on the network trying to arrive while this is occurring. These duplicate packets, or duplicate ACKs, need to be handled in order to keep the file transfer from becoming exponentially larger each time there was some sort of issue.…

    • 311 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    The 5-layer model serves essentially the protocols regarded as Transmission Control Protocol (TCP) as well as Internet Protocol (IP), or mutually, TCP/IP. The User Datagram Protocol (UDP) is likewise served by this particular model. The 5-layer model was produced alongside with these protocols, anteceding the 7-layer model, and is from time to time known as the TCP Model.…

    • 1263 Words
    • 5 Pages
    Powerful Essays
  • Satisfactory Essays

    Let A and B be two stations attempting to transmit on an ethernet. Each has a steady queue of frames ready to send; A’s frames will be numbered A1 , A2 and so on, and B’s similarly. Let T = 51.2 µs be the exponential backoff base unit. Suppose A and B simultaneously attempt to send frame 1, collide, and happen to choose backoff times of 0 x T and 1 x T, respectively. As a result, A transmits A1 while B waits. At the end of this transmission, B will attempt to retransmit B1 while A will attempt to transmit A2 . These first attempts will collide, but now A backs off for either 0 x T or 1 x T, while B backs off for time equal to one of 0 x T, ..., 3 X T. (a) Give the probability that A wins this second backoff race immediately after its first collision. (b) Suppose A wins the second backoff race. A transmits A3 and, when it is finished, A and B collide again as A tries to transmit A4…

    • 733 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Task 1, Step 6: Paste a screenshot showing the results of the ping tests to…

    • 447 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Nt1310 Unit 1

    • 4209 Words
    • 17 Pages

    83) Which process is responsible for establishing a connection between the client and the server?…

    • 4209 Words
    • 17 Pages
    Powerful Essays
  • Satisfactory Essays

    6. To what IP address is the DNS query message sent? Use ipconfig to determine the…

    • 671 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    What is the significance of the TCP three-way handshake for applications that utilize TCP as a transport…

    • 338 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    paper

    • 362 Words
    • 2 Pages

    4. If you ping the TargetWindows01 server and the UbuntuTarget01 server, which fields in the ICMP…

    • 362 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Midterm Exam

    • 2086 Words
    • 9 Pages

    B. The channel of the message is faulty, or else the correct term would be sent and received.…

    • 2086 Words
    • 9 Pages
    Good Essays
  • Good Essays

    To best addressing this issue let me explain about the network errors first. Network errors…

    • 366 Words
    • 2 Pages
    Good Essays