Skip to content

EthernetServer available() is confusing #1320

@lestofante

Description

@lestofante

Hi,
the EthernetServer.available() return the first socket connected (or waiting for close)with data in RX buffer.

This is bad because first of all user tends to think available() return the NEXT connected socked (even if it has no data into RX). Also if there are multiple client connected continually writing data to arduino (or writing it at right moment), there can be a situation where you will never be able to read the last EthernetClient.

We have found 3 solution (the last is probably the best):
-1. add a flag into EthernetClient: when returned by available() this client will never be returned thanks to this flag. The client is returned even is RX buffer is empty. Can break some code.

-2. add a EthernetServer.available(int) where user can choose what Sokcet use. but this should be invisible to user, as it can overflow the array or receive non-connected EthernetClient, advantagies is taht this is an overloaded methos, so old code will work.

-3. add a new method like EthernetServer.getNextClient() witch will use the flag method as 1. No retro-compatibility problem and an easy way to get all client connected. Also a method to get maximum number of client connected should be provided, or the constant "MAX_SOCK_NUM" should be public, so user can create it's own EthernetClient's array

thanks for your attention, here the discussion (in Italian): http://arduino.cc/forum/index.php/topic,154157.0.html

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions