Go Down

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

Øystein

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);
 server.begin();
}

void loop()
{

 int button1 = digitalRead(2);
 int button2 = digitalRead(3);
 
 if (button1 == HIGH)
 {
      server.println('1');
 }

 if (button2 == HIGH)
 {
      server.println('2');
 }
}[/size][/font]

Anybody has any suggestions for how to solve this?

Thank you.

zoomkat

Quote
Anybody has any suggestions for how to solve this?


You probably need to close the arduino connection like below.

 //stopping client
client.stop();
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Øystein

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

Quote
//stopping client
client.stop();


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.

zoomkat

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);
server.begin();

//enable serial data print
Serial.begin(9600);
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;
Serial.print(c);
}

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

///////////////
Serial.println(readString);

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

/////////////////////
//clearing string for next read
readString="";
 
}}}}}


Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)

Go Up