From 8ea6a1778c292935c815632f4bd96816f4d73dba Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 23 Jan 2023 16:28:08 -0600 Subject: [PATCH] license info for new file. use dhcp instaed of static. rename new example. --- ...iznet5k_cpython_client_for_simpleserver.py} | 18 ++++++++++++++---- examples/wiznet5k_simpleserver.py | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) rename examples/{client_for_wiznet5k_simpleserver.py => wiznet5k_cpython_client_for_simpleserver.py} (64%) diff --git a/examples/client_for_wiznet5k_simpleserver.py b/examples/wiznet5k_cpython_client_for_simpleserver.py similarity index 64% rename from examples/client_for_wiznet5k_simpleserver.py rename to examples/wiznet5k_cpython_client_for_simpleserver.py index 2a3b95e..ae89d8b 100755 --- a/examples/client_for_wiznet5k_simpleserver.py +++ b/examples/wiznet5k_cpython_client_for_simpleserver.py @@ -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 @@ -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) diff --git a/examples/wiznet5k_simpleserver.py b/examples/wiznet5k_simpleserver.py index 2392ebf..82a2cc3 100644 --- a/examples/wiznet5k_simpleserver.py +++ b/examples/wiznet5k_simpleserver.py @@ -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