Skip to content

Instantly share code, notes, and snippets.

@brianhsu
Created July 20, 2022 03:04
Show Gist options
  • Save brianhsu/dc326eee2558d90cc3d74315b40436c7 to your computer and use it in GitHub Desktop.
Save brianhsu/dc326eee2558d90cc3d74315b40436c7 to your computer and use it in GitHub Desktop.
import socket
import sys
import time
if len(sys.argv) == 3:
# Get "IP address of Server" and also the "port number" from argument 1 and argument 2
ip = sys.argv[1]
port = int(sys.argv[2])
else:
print("Run like : python3 client.py <arg1 server ip 192.168.1.102> <arg2 server port 4444 >")
exit(1)
# Create socket for server
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
s.bind((ip, port))
print("Do Ctrl+c to exit the program !!")
# Let's send data through UDP protocol
while True:
start_time = time.time_ns() // 1_000_000
data, address = s.recvfrom(1785)
duration = time.time_ns() // 1_000_000 - start_time
print(f"receive {duration}")
# close the socket
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment