Using the Arduino sketch below, in an Arduino Ethernet Rev 3 board, I see some blinks of the Arduino TX/RX LEDs that look like connection attempts, but the connection attempts never succeed. I also see blinking at my (desktop) network switch.
The "server" code is a python routine that is able to accept connections from a different python routine (both are in the same Windows computer) that I wrote for testing this sort of thing. I have posted snippets of the python routine.
This has got to be something simple; but I am stumped. I have searched the web for similar problems; and I have searched the first 15 pages of this site's "Networking, Protocols and Devices" history, all to no avail.
Hopefully someone will spot my problem, or remember how they solved a similar one, or will offer a checklist of things for me to double check.
Here is the Arduino "Client" code.
#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>
void setup()
{
// put your setup code here, to run once:
// ------------------- Ethernet Setup section ---------------------------//
byte myMac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0xB7, 0xE6 };
byte myIP[] = { 192, 168, 0, 10 };
byte dns[] = { 192, 168, 0, 1 };
byte gateway[] = { 192, 168, 0, 1 };
byte mySubnet[] = { 255, 255, 255, 0 };
byte serversIP[] = { 192, 168, 0, 2 };
int serversPort = 14531;
EthernetClient client;
Serial.begin(9600);
delay(1000);
Serial.println("5");
delay(1000);
Serial.println("4");
delay(1000);
Serial.println("3");
delay(1000);
Serial.println("2");
delay(1000);
Serial.println("1");
delay(1000);
Serial.println("0");
Ethernet.begin(myMac, myIP);
// Ethernet.begin(myMac, myIP, dns, gateway, mySubnet);
delay(1000);
Serial.print ("My IP = "); Serial.println (Ethernet.localIP());
Serial.print("connecting to port "); Serial.print(serversPort);
Serial.print(" at "); Serial.print(serversIP[0]);
Serial.print("."); Serial.print(serversIP[1]);
Serial.print("."); Serial.print(serversIP[2]);
Serial.print("."); Serial.print(serversIP[3]);
Serial.println("...");
// client.connect(serverIP, serversPort);
if (client.connect(serversIP, serversPort))
{
Serial.println("connected");
}
else
{
Serial.println("connection failed");
}
}
void loop()
{
// put your main code here, to run repeatedly:
}
Here are snippets of the "Server" python code:
...
addressFamily = AF_INET
connectionType = SOCK_STREAM
clientAddress = '192.168.0.2'
serverAddress = '192.168.0.2'
...
serversAcceptPort = 14531
serversAcceptNodeInfo = (serverAddress, serversAcceptPort)
talkToServerSocket = None
...
mySvrSock.bind(self.serversAcceptNodeInfo)
serverAcceptTimeout =10.0
mySvrSock.settimeout(serverAcceptTimeout)
mySvrSock.listen(0)
...
talkToClientSocket, talkToClientNodeInfo = mySvrSock.accept()
...
Any thoughts?
GBlakeR