Jython 2.7 中的 UDP
UDP in Jython 2.7
我正在尝试编写一个 python 函数来向远程主机发送 UDP 消息并接收回复,但我很难理解如何执行此操作。
我一直在看线程:Simple Python UDP Server: trouble receiving packets from clients other than localhost
我了解如何发送内容,但如何以正确的顺序发送和接收?
提前致谢。
请无视,我知道了..
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 3001
MESSAGE = "asd"
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data
我正在尝试编写一个 python 函数来向远程主机发送 UDP 消息并接收回复,但我很难理解如何执行此操作。 我一直在看线程:Simple Python UDP Server: trouble receiving packets from clients other than localhost
我了解如何发送内容,但如何以正确的顺序发送和接收?
提前致谢。
请无视,我知道了..
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 3001
MESSAGE = "asd"
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print "received message:", data