-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop-wait.py
More file actions
20 lines (14 loc) · 711 Bytes
/
stop-wait.py
File metadata and controls
20 lines (14 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from twisted.internet import reactor # responsible for running the event loop
from twisted.internet.protocol import DatagramProtocol # UDP Protocols
class StopAndWaitProtocol(DatagramProtocol):
def startProtocol(self):
self.transport.connect('localhost', 8000) # set destination
def datagramReceived(self, datagram: bytes, addr):
print(f"Received {datagram.decode()}")
def sendData(self, data):
self.transport.write(data.encode())
# Create instance of stop and wait protocol
protocol = StopAndWaitProtocol()
reactor.callLater(2, protocol.sendData, 'Hello world')
reactor.callLater(4, protocol.sendData, 'How are you?')
reactor.callLater(6, protocol.sendData, 'Bye!')