My WiFiShield, running as a Server, will accept up to four simultaneous client connections, but will only write to the oldest connection. When I close the oldest client connection, which is the one receiving the buffer contents, the next oldest client connection receives the buffer contents.
The documentation for WiFiServer::write(buffer, size) states that it writes the contents of buffer to all connected clients. Am I not using the library correctly or is this a defect?
I have an Arduino WiFi Shield Model R3. I believe I have upgraded it to the version of wifiHD.hex and wifi_dnld.hex included with the IDE version 1.0.5 in the arduino-1.0.5/hardware/arduino/firmwares/wifishield/binary directory. Their MD5 checksums are:
wifiHD.hex de19a58da72dfb0ea3d30b0e93b5202c
wifi_dnld.hex 6b965a8361723c9121749cee205487f5
I originally attempted to use the script ArduinoWifiShield_upgrade.sh from the same IDE version, but it doesn't work correctly on my ubuntu 12.04 desktop. I had to execute the dfu-programmer commands manually, from the command line.
The output of WiFi.firmwareVersion() is "1.1.0".
I built the following sketch with the Arduino IDE version 1.0.5. It was uploaded to an Arduino Mega 2560. The only connections to the Mega are the WiFiShield and the USB cable.
billmania:
My WiFiShield, running as a Server, will accept up to four simultaneous client connections, but will only write to the oldest connection. When I close the oldest client connection, which is the one receiving the buffer contents, the next oldest client connection receives the buffer contents.
The documentation for WiFiServer::write(buffer, size) states that it writes the contents of buffer to all connected clients. Am I not using the library correctly or is this a defect?
It is a defect. The WiFi shield uses only one socket for the server. It will accept connections with that one socket from multiple clients before completing the previous client transaction. It will mix up the connections as you describe. Since it uses only one socket, It should accept only one client at a time, and not accept any further connections until that client is finished and disconnected. But it doesn't.
The tcp and udp client parts work ok. Just the listener (server) parts of the wifi library have this bug.
edit: And when I say the client parts work ok, that is after correcting a couple bugs. Here they are: