-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from e28eta/patch-1
Update SimpleServer example to accept >1 connection
- Loading branch information
Showing
2 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# SPDX-FileCopyrightText: 2023 ladyada | ||
# | ||
# SPDX-License-Identifier: MIT | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
This example client runs on CPython and connects to / sends data to the | ||
simpleserver example. | ||
""" | ||
import socket | ||
import time | ||
|
||
print("A simple client for the wiznet5k_simpleserver.py example in this directory") | ||
print( | ||
"Run this on any device connected to the same network as the server, after " | ||
"editing this script with the correct HOST & PORT\n" | ||
) | ||
# Or, use any TCP-based client that can easily send 1024 bytes. For example: | ||
# python -c 'print("1234"*256)' | nc 192.168.10.1 50007 | ||
|
||
|
||
# edit host and port to match server | ||
HOST = "192.168.10.1" | ||
PORT = 50007 | ||
TIMEOUT = 10 | ||
INTERVAL = 5 | ||
MAXBUF = 1024 | ||
|
||
while True: | ||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
s.settimeout(TIMEOUT) | ||
print(f"Connecting to {HOST}:{PORT}") | ||
s.connect((HOST, PORT)) | ||
# wiznet5k_simpleserver.py wants exactly 1024 bytes | ||
size = s.send(b"A5" * 512) | ||
print("Sent", size, "bytes") | ||
buf = s.recv(MAXBUF) | ||
print("Received", buf) | ||
s.close() | ||
time.sleep(INTERVAL) |
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