TCP client ou serveur

25 Feb 2014

Hello, the program below (from the site). The program gets stuck on server.accep (client); why? Mbed should communicate with my pc via ethernet (hardware OK as another example since it happens to send emails). the ip address is 192.168.0.102 mbed and that of pc 192.168.1.2

thank you for your help

  1. include "mbed.h"
  2. include "EthernetInterface.h"
  3. include "MODSERIAL.h"
  4. define ECHO_SERVER_PORT 3333
  5. define BAUD 9600

Serial pc(USBTX, USBRX);

int main (void) { pc.baud(BAUD); EthernetInterface eth; eth.init(); Use DHCP eth.connect(); printf("IP Address is %s\n", eth.getIPAddress());

TCPSocketServer server; server.bind(ECHO_SERVER_PORT); server.listen();

while (true) { printf("\nWait for new connection...\n"); TCPSocketConnection client; printf(" 1\n\r"); server.accept(client); printf(" 2\n\r"); client.set_blocking(false, 150000); Timeout after (1.5)s

printf("Connection from: %s\n", client.get_address()); char buffer[256]; while (true) { int n = client.receive(buffer, sizeof(buffer)); if (n <= 0) break;

client.send_all(buffer, n); if (n <= 0) break; }

client.close(); } }

25 Feb 2014

If I place the mbed on the same router (it works) ip address PC is 192.168.1.2 and the IP address of mbed is 192.168.1.4 it works OK.

What if I want to put the mbed to another router or IP address is 192.168.0.102 will??