python socket connecting to different subnet/domain -
Is it possible to connect to a different subnet or domain through python socket programming?
I want to create a script to share files with friends, but at present I only connect to a LAN.
In LAN, you can broadcast packets to find each other.
And every colleague should listen to the port to receive the broadcast.
This is a search protocol, you can implement it via UDP socket.
Once the two colleagues decide to communicate, they should make a TCP socket. Then, they can send data through TCP.
or you can use HTTP, XML-RPC, etc. to transfer data. (Not broadcast, TCP does not support broadcast).
#udp broadcast import socket, time s = socket.socket (socket.AF_INET, socket.SOCK_DGRAM) s.setsockopt (socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while correct Is: data = 'test'.encode () s.sendto (data, (' 255.255.255.255 ', 1080)) time.sleep (1)
#udp Broadcast import socket s = socket.socket (socket .finnette, socket.SOCIDARAM) s. Bind (('', 1080)) is true: print (SRCV (1024))
Comments
Post a Comment