Last active
February 23, 2022 13:57
-
-
Save ssrlive/881c4ba0e6777a71eecefdf98f1329b0 to your computer and use it in GitHub Desktop.
udp-cli.py
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
#!/usr/bin/python | |
''' | |
python UDP echo client by ccc <yyy@gmail> | |
USAGE: %s <server_ip> <server_port> <message> | |
''' | |
import socket | |
import time | |
from sys import argv | |
def echoUdpData(host, port, msg): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
print('connect to server: ', host, port) | |
print('send msg: ', msg) | |
sock.sendto(msg.encode('utf-8'), (host, port)) | |
sock.settimeout(3) | |
try: | |
data, addr = sock.recvfrom(1024) | |
print('recv msg: ', data.decode('utf-8')) | |
except: | |
print('Failed. socket.recvfrom time out') | |
sock.close() | |
print('>>>Start ...') | |
if __name__ == '__main__': | |
if len(argv) !=4: | |
print(__doc__ % argv[0]) | |
else: | |
echoUdpData(argv[1], int(argv[2]), argv[3]) | |
print('>>>END!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test suits.