találtam egy minta kódot a neten egy másik fórumban... elvileg másnak ez működött... nálam persze nem megy... kipróbálná valaki? mondjuk nálam a dhcp-s résznél már leakadt, de adtam neki IP címet, és így sem működött még az első kliens sem.
Lehet, hogy az Ethernet library-m a hibás???
/* EthernetClient example modified to support two Clients */
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(173,194,33,104); // Google
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
EthernetClient client2;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("Connecting first client...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("Client 1 connected");
// Make a HTTP request:
client.println("GET /search?q=galileogen1 HTTP/1.0");
client.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("Connection failed in client 1");
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("Connecting second client...");
// if you get a connection, report back via serial:
if (client2.connect(server, 80)) {
Serial.println("Client 2 connected");
// Make a HTTP request:
client2.println("GET /search?q=galileogen2 HTTP/1.0");
client2.println();
}
else {
// if you didn't get a connection to the server:
Serial.println("Connection failed in client 2");
}
Serial.println("");
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
Serial.println("CLIENT 1");
for (int i = 0; i <= 70; i++){
char c = client.read();
Serial.print(c);
}
Serial.println("");
Serial.println("");
}
delay (2500);
if (client2.available()) {
char d = client2.read();
Serial.println("CLIENT 2");
for (int i = 0; i <= 70; i++){
char d = client2.read();
Serial.print(d);
}
Serial.println("");
Serial.println("");
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting Client 1.");
client.stop();
}
// if the server's disconnected, stop the client:
if (!client2.connected()) {
Serial.println();
Serial.println("Disconnecting Client 2.");
client2.stop();
}
}