Skip to content

check recv size #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions adafruit_wiznet5k/adafruit_wiznet5k.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def __init__(
self.mac_address = mac
self.src_port = 0
self._dns = 0

# Set DHCP
self._dhcp_client = None
if is_dhcp:
Expand All @@ -196,6 +197,17 @@ def set_dhcp(self, hostname=None, response_timeout=30):
"""
if self._debug:
print("* Initializing DHCP")

# First, wait link status is on
# to avoid the code during DHCP - assert self.link_status, "Ethernet cable disconnected!"
start_time = time.monotonic()
while True:
if self.link_status or ((time.monotonic() - start_time) > 5):
break
time.sleep(1)
if self._debug:
print("My Link is:", self.link_status)

# Return IP assigned by DHCP
self._dhcp_client = dhcp.DHCP(
self, self.mac_address, hostname, response_timeout, debug=self._debug
Expand Down
9 changes: 5 additions & 4 deletions examples/wiznet5k_simpleserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
server.bind((server_ip, server_port)) # Bind to IP and Port
server.listen() # Begin listening for incoming clients

conn, addr = server.accept() # Wait for a connection from a client.
while True:
conn, addr = server.accept() # Wait for a connection from a client.
with conn:
data = conn.recv()
print(data)
conn.send(data) # Echo message back to client
data = conn.recv(1024)
if data: # Wait for receiving data
print(data)
conn.send(data) # Echo message back to client