Add a udp program and a ping test script
This commit is contained in:
parent
9355acf903
commit
d31be8cba0
2 changed files with 63 additions and 0 deletions
18
ping.py
Normal file
18
ping.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import socket
|
||||
import sys
|
||||
import time
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
addr = ('localhost', 26099)
|
||||
sock.bind(addr)
|
||||
|
||||
|
||||
print("pinging...", file=sys.stderr)
|
||||
while True:
|
||||
buf, raddr = sock.recvfrom(4096)
|
||||
print("receive: " + buf.decode("utf-8"))
|
||||
buf = "this is a ping to port 6200!".encode('utf-8')
|
||||
sock.sendto(buf, ("127.0.0.1", 6200))
|
||||
buf = "this is a ping to reply!".encode('utf-8')
|
||||
sock.sendto(buf, raddr)
|
||||
time.sleep(1)
|
Loading…
Add table
Add a link
Reference in a new issue