// Player 2 #include "mbed.h" #include "EthernetInterface.h" const char* PLAYER1_IP = "192.168.2.1"; const char* PLAYER2_IP = "192.168.2.2"; const int SERVER_PORT = 7; Serial pc(USBTX, USBRX); int main() { EthernetInterface eth; eth.init(PLAYER2_IP, "255.255.255.0", "0.0.0.0"); //Use DHCP eth.connect(); pc.printf("\nClient IP Address is %s\n", eth.getIPAddress()); // Connect to Server TCPSocketConnection socket; while (socket.connect(PLAYER1_IP, SERVER_PORT) < 0) { pc.printf("Unable to connect to (%s) on port (%d)\n", PLAYER1_IP, SERVER_PORT); //wait(1); } pc.printf("Connected to Server at %s\n",PLAYER1_IP); // Send message to server char hello[] = "Hello World"; pc.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'; pc.printf("Received message from server: '%s'\n", buf); // Clean up socket.close(); eth.disconnect(); while(true) {} }