I'm using the shield on a Mega, running the ethernet in server mode. The client connects and sends text to the arduino and receives text back, and remains connected until the client disconnects.
This all works fine, as long as only one client is connected. If a second client connects, the Arduino becomes nonresponsive to the other client. It seems to cache a bit of activity from the 'frozen' client, which is then acted on when the other client disconnects.
Looking through the documentation and the library sources, I think the problem lies in the fact that there doesn't seem to be a way to get a client object for more than one connection. You use server.available() which
However, in getting 'a' client, it doesn't seem to have provision to get more than one client, or rather, to get additional clients should they exist.Gets a client that is connected to the server and has data available for reading. The connection persists when the returned client object goes out of scope
The source for server.available() looks like it just counts up through the four available sockets and returns the first one that has a connection:
Code: Select all
EthernetClient EthernetServer::available() {
accept();
for (int sock = 0; sock < MAX_SOCK_NUM; sock++) {
EthernetClient client(sock);
if (EthernetClass::_server_port[sock] == _port &&
(client.status() == SnSR::ESTABLISHED ||
client.status() == SnSR::CLOSE_WAIT)) {
if (client.available()) {
// XXX: don't always pick the lowest numbered socket.
return client;
}
}
}
return EthernetClient(MAX_SOCK_NUM);
}
So it doesn't look like it would help if I tried calling server.available four times over, assigning each call to a different client.. so this would probably just return four instances of the very same connection:
Code: Select all
EthernetClient client1 = server.available();
EthernetClient client2 = server.available();
EthernetClient client3 = server.available();
EthernetClient client4 = server.available();
Thanks!