// Mbed B #include "mbed.h" #include "EthernetInterface.h" #include "uLCD_4DGL.h" DigitalOut l1(LED1); DigitalOut l2(LED2); DigitalOut l3(LED3); DigitalOut l4(LED4); uLCD_4DGL uLCD (p9,p10,p8); // serial tx, serial rx, reset pin; const int ECHO_SERVER_PORT = 7; const char* ECHO_SERVER_ADDRESS = "192.168.1.1"; // Adress from other Mbed int main () { EthernetInterface eth; const char* ip = "192.168.1.2"; // MBED A = 1; MBED B = 2 const char* mask = "255.255.255.0"; const char* gateway = "192.168.1.10"; eth.init(ip, mask, gateway); //I'dont use DHCP bacuse i use two mbeds eth.connect(); uLCD.printf("Client IP Address is %s\n", eth.getIPAddress()); // Connect to Server TCPSocketConnection socket; while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0) { uLCD.printf("Unable to connect to (%s) \non port (%d)\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT); wait(1); } uLCD.printf("Connected to Server at %s\n",ECHO_SERVER_ADDRESS); // Send message to server char hello[] = "Hello World"; uLCD.printf("Sending message to Server : '%s' \n",hello); socket.send_all(hello, sizeof(hello) - 1); // Receive message from server char buf[256]; int n = socket.receive(buf, 256); buf[n] = '\0'; uLCD.printf("Received message from server: '%s'\n", buf); // Clean up socket.close(); eth.disconnect(); while(true) {} }