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
- include "mbed.h"
- include "EthernetInterface.h"
- include "MODSERIAL.h"
- define ECHO_SERVER_PORT 3333
- 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();
}
}
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
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(); } }