Go Down

Topic: Ethernet shield / max 4 connections (Read 6940 times) previous topic - next topic


Hi all,
I'm new to this forum, and I haven't found an answer to my problem anywhere else so hence this posting. I apologize if there is indeed an answer somewhere else.

I have an Arduino UNO with an Ethernet shield. I realize that the Ethernet shield has a max of 4 simultaneous connections. However, I'm experiencing problems with having more than 4 consecutive connections as well. That is, a client connects, reads the data, and disconnects. Then, later on, another client connects/reads/disconnections, etc. After 4 of these, it won't allow any more connections. My clients are doing the appropriate closing, etc. of the socket on their side, so this seems like an issue on the Arduino side to me.

The code I have on the Arduino side is prety simple:

[font=Courier][size=11]byte mac[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
byte ip[] = { 192, 168, 1, 2 };

Server server = Server(23);

void setup()
 pinMode(2, INPUT);
 pinMode(3, INPUT);

 Ethernet.begin(mac, ip);

void loop()

 int button1 = digitalRead(2);
 int button2 = digitalRead(3);
 if (button1 == HIGH)

 if (button2 == HIGH)

Anybody has any suggestions for how to solve this?

Thank you.


Anybody has any suggestions for how to solve this?

You probably need to close the arduino connection like below.

 //stopping client
Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.


Jan 24, 2011, 03:30 am Last Edit: Jan 24, 2011, 03:31 am by oybed Reason: 1
Thank you.

//stopping client

At this point I don't have a reference to the client that is connected (see code posted earlier). I supposed that means re-writing the implementation? I tried something like that earlier and couldn't make it work either, but I'll try again.


Some simple server test code I use.

Code: [Select]
//zoomkat 12-18-10
//routerbot code
//for use with IDE 0021
//open serial monitor to see what the arduino receives

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
Server server(84); //server port

String readString;


void setup(){

//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);

//enable serial data print
Serial.println("servertest1"); // so I can keep track of what is loaded

void loop(){
// Create a client connection
Client client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();

//read char by char HTTP request
if (readString.length() < 100) {

//store characters to string
readString += c;

//if HTTP request has ended
if (c == '\n') {


 //now output HTML data header
 client.println("HTTP/1.1 204 Zoomkat");
 //stopping client

//clearing string for next read

Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131