Hi all,
I'm programming a tcp/ip pc/arduino project. The Arduino has a ethernetshield and serves as client. The PC runs boost and makes use of the asio library and serves as client.
When i try to connect to the server the connection can not be establised. The server has a network adapter that has the static aderes of 192.168.1.1. And the Arduino has IP adress of 192.168.1.2. The two are directly connected with a UTP cable. Both are using port 5000.
When i ping the arduino from my pc, then that works fine.
For the Arduino code i use a sample program to for testing but this fails. The setup looks like this:
// Enter the IP address of the server you're connecting to:
IPAddress server(192,168,1,1);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 23 is default for telnet;
// if you're using Processing's ChatServer, use port 10002):
EthernetClient client;
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac, ip);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 5000)) {
Serial.println("connected");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
The PC server code is also fairly simple, in a class constructor i do the following:
cout << "Setting up server" << endl;
// Protocol and port
boost::asio::ip::tcp::endpoint Endpoint(boost::asio::ip::tcp::v4(), 5000);
// Create acceptor
boost::asio::ip::tcp::acceptor Acceptor(IOService, Endpoint);
// Create socket
SmartSocket Sock(new boost::asio::ip::tcp::socket(IOService));
cout << "Before accept..." << endl;
// Waiting for client
Acceptor.accept(*Sock);
cout << "Server set up" << endl;
SmartSocket is a typdef:
typedef boost::shared_ptrboost::asio::ip::tcp::socket SmartSocket;
I i start the server the console prints "Before Accept" and waits in the accept function for a incomming client. But when i run my Arduino code then i get connection failed (in the ardunion serial monitor).
Does anybody have some idea's what is going wrong? It seems that the server and client don't see each other. I also put down my firewall but this didn't help. Any comments are usefull!