There is a bug in the Arduino 0013 Ethernet library.
A second connection to the same server doesn´t work. Only the first connection will work. Exact same code works fine in Arduino 0012.
I need the new float feature in the 0013 Ethernet libarary. So it would be nice if you fix it or release a work around. Thanks.
Ethernet ChatServer Online
31000
Client Message Sent
ARDUINO ROCKS!
647
I have a simple tcplistener running on my computer that echoes back whatever it receives. As you can see it works on the first attempt and is about to attempt again after the 647. But, that is it, nothing happens after that. If the connect failed it should keep spitting out 647 until it connects because that value is not reset until a connection is made. So it seems the Arduino simply hangs at that point.
Tested it with the code above, but modified to use the standard "echo" service on port 7. Got a few TCP connection listed as open before the code somehow went into a "loop" writing the number "31075" to the serial console...
I tested kmm's fix and it seemed to do the trick. But I was still having a problem my TCPListener program not receiving any subsequent messages because it still thought the first connection was open. I was able to get around this by adding a client.stop() after sending a message. Looking at it now it's probably better to use the client.connected() to see if you are still connected rather than creating a new connection each time. It may still be a good idea to add:
if (connected())
stop();
or maybe:
if (connected())
return 1;
to the begining of uint8_t Client::connect() in client.cpp? What do you guys think?
I went ahead and modified the library to be compatible with Sanguino. It tested fine with the modifications on both Arduino and Sanguino.
Unfortunately, I spent an hour and a half up against this bug last night trying to figure out what I was doing wrong in my code. It didn't even occur to me that it might be a bug in the library. I figured it had to be my code, because, well, I'm new to this.
Glad to know it wasn't my code. An extra hour and a half of sleep would be nice, though....
I made those changes but I think I have another problem, after 5 connections (one after another ... not at the same time) ... the arduino refuses any connection for about a minute ? Is there something I should be calling to free up those connections, besides client.stop(); ?
#include <Ethernet.h>
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xEF, 0xED };
byte ip[] = {192, 168, 0, 10 };
int CurrentTime = 0;
const int TimeOutMax = 6000;
boolean DebugMode = true;
Server server = Server(23);
void setup()
{
pinMode(StatusLED, OUTPUT); // sets the digital pin as output
digitalWrite(StatusLED, HIGH);
pinMode(Learner, INPUT);
pinMode(IR1, OUTPUT);
pinMode(IR2, OUTPUT);
pinMode(IR3, OUTPUT);
pinMode(IR4, OUTPUT);
digitalWrite(StatusLED, LOW);
delay(200);
Ethernet.begin(mac, ip);
server.begin();
digitalWrite(StatusLED, HIGH);
Serial.begin(9600);
}
void loop()
{
Client client = server.available();
if (client)
{
if (DebugMode)
{
Serial.println("Connected");
}
byte ReadyChar;
ReadyChar = client.read();
if (ReadyChar == 0)
{
}
if (ReadyChar == 255)
{
client.write(255);
GetCommandData(client);
client.stop();
}
}
else
{
if (DebugMode)
{
Serial.println("Not Connected");
}
}
}
There is more too it if you want to see it all, but there is normally 10 seconds between connections (sometimes a little less or more). I timed the code to get from the Serial.println("Not Connected"); back to that statement after it connects transfers data and does it thing then back to saying "Not Connected" normally takes about 400 ms.
I will post the rest of it this evening, but I added the client.stop(); because it wasn't working (it didn't help)
I'm trying to send IR codes to the ardunio then have it flash an emitter to turn my TV on and off, I have an IPAQ running a .net app that takes a standard IR hex code converts it to number of burst pairs, clock speed, and an array or on times and off times. I want to send those to the arduino and once it has the complete information I want to it flash the emitter and send it (which all of that works) the problem comes when I want to send multiple IR codes in a row (example I want to scan though the guide or something ... pushing the guide button then the up or down arrow a couple times) thats when the .net application gets an error saying the arduino actively refused the connection