Predict the contents of each field of the UDP header and payload data. You do no
ID: 3744869 • Letter: P
Question
Predict the contents of each field of the UDP header and payload data. You do not need to include any of the lower-level IP or Ethernet headers. In a table, create one row for each field of the UDP packet header and the payload. Within the row for each field, include the name of the field the number of bytes that field uses the value you predict for the header in a "human readable" format (for example, as a decimal number or a string) the raw value of the field, written as a hexadecimal number. You do not need to predict the value of the checksum or the source port. See the Lab 1 Example Format that illustrates the required components (using an IP header for an example). See the next section for a description of the fields used in the UDP packet.Explanation / Answer
import socket,time,traceback
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dstHost = ('192.168.1.100', 12345)
while True:
try:
client.sendto('3',dstHost)
print time.time(),' : send success'
time.sleep(3)
except:
traceback.print_exc()
UDP Server Program
import socket
localIP = "127.0.0.1"
localPort = 20001
bufferSize = 1024
msgFromServer = "Hello UDP Client"
bytesToSend = str.encode(msgFromServer)
UDPServerSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
UDPServerSocket.bind((localIP, localPort))
print("UDP server up and listening")
while(True):
bytesAddressPair = UDPServerSocket.recvfrom(bufferSize)
message = bytesAddressPair[0]
address = bytesAddressPair[1]
clientMsg = "Message from Client:{}".format(message)
clientIP = "Client IP Address:{}".format(address)
print(clientMsg)
print(clientIP)
UDPServerSocket.sendto(bytesToSend, address)
UDP Client using Python
import socket
msgFromClient = "Hello UDP Server"
bytesToSend = str.encode(msgFromClient)
serverAddressPort = ("127.0.0.1", 20001)
bufferSize = 1024
UDPClientSocket = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
UDPClientSocket.sendto(bytesToSend, serverAddressPort)
msgFromServer = UDPClientSocket.recvfrom(bufferSize)
msg = "Message from Server {}".format(msgFromServer[0])
print(msg)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.