Skip to content

Commit 8ea6a17

Browse files
committed
license info for new file. use dhcp instaed of static. rename new example.
1 parent 5003ca3 commit 8ea6a17

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

examples/client_for_wiznet5k_simpleserver.py renamed to examples/wiznet5k_cpython_client_for_simpleserver.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1+
# SPDX-FileCopyrightText: 2023 ladyada
2+
#
3+
# SPDX-License-Identifier: MIT
14
#!/usr/bin/env python3
5+
6+
"""
7+
This example client runs on CPython and connects to / sends data to the
8+
simpleserver example.
9+
"""
210
import socket
311
import time
412

513
print("A simple client for the wiznet5k_simpleserver.py example in this directory")
6-
print("Run this on any device connected to the same network as the server, after "
7-
"editing this script with the correct HOST & PORT\n")
14+
print(
15+
"Run this on any device connected to the same network as the server, after "
16+
"editing this script with the correct HOST & PORT\n"
17+
)
818
# Or, use any TCP-based client that can easily send 1024 bytes. For example:
919
# python -c 'print("1234"*256)' | nc 192.168.10.1 50007
1020

@@ -22,9 +32,9 @@
2232
print(f"Connecting to {HOST}:{PORT}")
2333
s.connect((HOST, PORT))
2434
# wiznet5k_simpleserver.py wants exactly 1024 bytes
25-
size = s.send(b'A5'*512)
35+
size = s.send(b"A5" * 512)
2636
print("Sent", size, "bytes")
2737
buf = s.recv(MAXBUF)
28-
print('Received', buf)
38+
print("Received", buf)
2939
s.close()
3040
time.sleep(INTERVAL)

examples/wiznet5k_simpleserver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
1919

2020
# Initialize ethernet interface
21-
eth = WIZNET5K(spi_bus, cs, is_dhcp=False)
21+
eth = WIZNET5K(spi_bus, cs, is_dhcp=True)
2222

2323
# Initialize a socket for our server
2424
socket.set_interface(eth)
2525
server = socket.socket() # Allocate socket for the server
26-
server_ip = "192.168.10.1" # IP address of server
26+
server_ip = eth.pretty_ip(eth.ip_address) # IP address of server
2727
server_port = 50007 # Port to listen on
2828
server.bind((server_ip, server_port)) # Bind to IP and Port
2929
server.listen() # Begin listening for incoming clients

0 commit comments

Comments
 (0)