Receiving Broadcast Packets in Python

后端 未结 3 2088
無奈伤痛
無奈伤痛 2020-12-13 18:39

I have the following code which sends a udp packet that is broadcasted in the subnet.

from socket import *
s=socket(AF_INET, SOCK_DGRAM)
s.setso         


        
3条回答
  •  不知归路
    2020-12-13 19:26

    s=socket(AF_INET, SOCK_DGRAM)
    s.bind(('',1234))
    while(1):
        m=s.recvfrom(4096)
        print 'len(m)='+str(len(m))
        print 'len(m[0])='+str(len(m[0]))    
        print m[0]
    
        print 'len(m[1])='+str(len(m[1]))    
        print m[1]  
    

提交回复
热议问题