python网络编程(五)
udp广播
#coding=utf-8 import socket, sys dest = ('<broadcast>', 7788) # 创建udp套接字 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # 对这个需要发送广播数据的套接字进行修改设置,否则不能发送广播数据 s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) # 以广播的形式发送数据到本网络的所有电脑中 s.sendto("Hi", dest) print "等待对方回复(按ctrl+c退出)" while True: (buf, address) = s.recvfrom(2048) print "Received from %s: %s" % (address, buf)
相关推荐
架构技术交流 2020-04-14
kikaylee 2020-03-03
Unimen 2020-06-25
MAC2007 2020-06-06
安辉 2020-05-05
diediexiaomi 2020-04-21
taishanduba 2020-04-11
kkpiece 2020-03-03
vanturman 2020-02-10
朱建伟 2020-01-10
jackalwb 2020-01-01
TinyDolphin 2020-01-10
shengge0 2020-01-08
apowerfulman 2020-01-07
OwenJi 2019-12-29
HongKongPython 2019-12-29
zhouhaihua00 2019-12-26