Access over 35 million academic & study documents

Networkprogramming

Content type
User Generated
Subject
Python
School
Pace University - New York
Type
Homework
Rating
Showing Page:
1/8
Running head: NETWORK PROGRAMMING 1
Python network programming
Name
Institution
Course Number
Course Title
Date

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/8
PYTHON NETWORK PROGRAMMING 2
[HW6.a] (5pts) Convert the code of udp client and server in object-oriented paradigm. Class
should be defined and an object is constructed. For example,
UDP Server
from socket import *
class UDPserver:
def __init__(self):
self.s = socket(AF_INET, SOCK_DGRAM)
def binding(self, port):
# binding the port
self.s.bind(port)
def talking(self):
while True:
# receiving the data
data, addr = self.s.recvfrom(2020)
data = data.decode()
# printing data from client
print("From Client: ", data)
# sending back to server
self.s.sendto(data.encode(), addr)
# below is to use the class
udp1 = UDPserver()
udp1.binding(("127.0.0.1", 3030))
udp1.talking()

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/8

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 8 pages?
Access Now
Unformatted Attachment Preview
Running head: NETWORK PROGRAMMING Python network programming Name Institution Course Number Course Title Date 1 PYTHON NETWORK PROGRAMMING [HW6.a] (5pts) Convert the code of udp client and server in object-oriented paradigm. Class should be defined and an object is constructed. For example, UDP Server from socket import * class UDPserver: def __init__(self): self.s = socket(AF_INET, SOCK_DGRAM) def binding(self, port): # binding the port self.s.bind(port) def talking(self): while True: # receiving the data data, addr = self.s.recvfrom(2020) data = data.decode() # printing data from client print("From Client: ", data) # sending back to server self.s.sendto(data.encode(), addr) # below is to use the class udp1 = UDPserver() udp1.binding(("127.0.0.1", 3030)) udp1.talking() 2 PYTHON NETWORK PROGRAMMING UDP Client from socket import * class UdpClientClass: def __init__(self): self.c = socket(AF_INET, SOCK_DGRAM) def talking(self, msg, port): # sending msg to server self.c.sendto(msg, port) # receiving data from server data, addr = self.c.recvfrom(2020) print("From Server : " + data.decode()) # below is to use the class for ping in range(10): client = UdpClientClass() client.talking("hello".encode(), ("127.0.0.1", 3030)) Screenshot 3 PYTHON NETWORK PROGRAMMING [HW6.b] (5 pts) Write tcp socket programs for server and client. The both server and client programs should communicate interactively. One requirement is to display your name in the dialog. A sample run is sh ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Just what I needed…Fantastic!

Studypool
4.7
Indeed
4.5
Sitejabber
4.4