mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-25 02:46:23 +04:00
19 lines
497 B
Python
19 lines
497 B
Python
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)
|