我正在尝试编写一个程序来发送UDP数据包,就像https://wiki.python.org/moin/UdpCommunication中看到的那样。该代码似乎是使用Python 2编写的:
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Hello, World!"
print "UDP target IP:", UDP_IP
print "UDP target port:", UDP_PORT
print "message:", MESSAGE
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
如果我在要打印的内容周围加上圆括号,它会在屏幕上打印出来。
我需要做什么才能使其生效?