I am having the same issue. It hangs the Arduino completely on the second connection attempt. Here is the code I am using:
Code:#include <Ethernet.h>
// network configuration. gateway and subnet are optional.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 178 };
byte server[] = { 192, 168, 1, 54 };
Client client(server, 13000);
long timerX = 31000;
void setup()
{
// initialize the ethernet device
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("Ethernet ChatServer Online");
}
void loop()
{
if (client.available())
{
while (client.available())
{
char c = client.read();
Serial.print(c);
}
}
long currentTime = millis();
if (abs(currentTime - timerX) > 10000)
{
Serial.println(timerX);
if (client.connect())
{
client.println("Arduino Rocks!");
timerX = millis();
Serial.println("Client Message Sent");
}
}
}
Here is what I get back in the serial monitor:
Code: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.