Created
April 11, 2016 17:47
-
-
Save anonymous/f9d3c1ce71968a1787dd006bea5048c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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