Skip to content

Commit

Permalink
license info for new file. use dhcp instaed of static. rename new exa…
Browse files Browse the repository at this point in the history
…mple.
  • Loading branch information
FoamyGuy committed Jan 23, 2023
1 parent 5003ca3 commit 8ea6a17
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# 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")
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

Expand All @@ -22,9 +32,9 @@
print(f"Connecting to {HOST}:{PORT}")
s.connect((HOST, PORT))
# wiznet5k_simpleserver.py wants exactly 1024 bytes
size = s.send(b'A5'*512)
size = s.send(b"A5" * 512)
print("Sent", size, "bytes")
buf = s.recv(MAXBUF)
print('Received', buf)
print("Received", buf)
s.close()
time.sleep(INTERVAL)
4 changes: 2 additions & 2 deletions examples/wiznet5k_simpleserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialize ethernet interface
eth = WIZNET5K(spi_bus, cs, is_dhcp=False)
eth = WIZNET5K(spi_bus, cs, is_dhcp=True)

# Initialize a socket for our server
socket.set_interface(eth)
server = socket.socket() # Allocate socket for the server
server_ip = "192.168.10.1" # IP address of server
server_ip = eth.pretty_ip(eth.ip_address) # IP address of server
server_port = 50007 # Port to listen on
server.bind((server_ip, server_port)) # Bind to IP and Port
server.listen() # Begin listening for incoming clients
Expand Down

0 comments on commit 8ea6a17

Please sign in to comment.