Skip to content

Instantly share code, notes, and snippets.

Created April 11, 2016 17:47
Show Gist options
  • Save anonymous/f9d3c1ce71968a1787dd006bea5048c4 to your computer and use it in GitHub Desktop.
Save anonymous/f9d3c1ce71968a1787dd006bea5048c4 to your computer and use it in GitHub Desktop.
import socket
LOCAL_IP = "0.0.0.0"
LOCAL_PORT = 34197
REMOTE_IP = "myserverintheweb.xyz"
REMOTE_PORT = 20000
if __name__ == "__main__":
sock = socket.socket( socket.AF_INET,
socket.SOCK_DGRAM)
sock.bind((LOCAL_IP, LOCAL_PORT))
sock.sendto(bytes(MESSAGE, 'UTF-8'), (REMOTE_IP, REMOTE_PORT))
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
print(data)
import socket
UDP_IP = "0.0.0.0"
UDP_PORT = 20000
if __name__ == "__main__":
sock = socket.socket( socket.AF_INET,
socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
response = '{0}:{1}'.format(addr[0], addr[1])
sock.sendto(bytes(response, 'UTF-8'), addr)
import time
import socket
LOCAL_ADDRESS = ("0.0.0.0", 34197)
CLIENT_ADDRESSES = [
("yyy.yyy.yyy.yyy", 34197),
("zzz.zzz.zzz.zzz", 34197)
]
if __name__ == "__main__":
sock = socket.socket( socket.AF_INET,
socket.SOCK_DGRAM)
sock.bind(LOCAL_ADDRESS)
print("sending packets to clients")
while True:
for client in CLIENT_ADDRESSES:
sock.sendto(bytes("foobar", 'UTF-8'), client)
time.sleep(2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment