Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 2 months ago.
Wifly TCPSocketServer problems - Help - please !
The code below is modified from the Echo Server example. The Wifly connects fine but I cannot get the TCPSocketServer to work. If I try to Telnet to port 2000, I can get the command interface, but there is no response from port 12345. Also, when connecting with Telnet on port 2000, the code below gets executed ("Connecting from..."). What am I missing here ? I need a Socket Server on port 12345, not a client. Please help.
#include "mbed.h" #include "WiflyInterface.h" Serial pc(USBTX, USBRX); WiflyInterface wifly(p28, p27, p26, p25, "SSID", "password", WPA); // m3pi int main (void) { wifly.init(); // use DHCP while (!wifly.connect()); // join the network TCPSocketServer server; server.bind(12345); server.listen(1); while (true) { printf("\nWait for new connection...\r\n"); TCPSocketConnection client; server.accept(client); client.set_blocking(false, 10000); printf("Connection from: %s\n\r", 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(); } }
Question relating to:
1 Answer
12 years, 2 months ago.
Hi Rolf,
It appears that on some wifly modules, the module has to be rebooted to change the local port (on which the module is listening). I updated the wiflyinterface library. You can even find a program example at the end of the WiflyInterface webpage using TCPSocketServer.
Cheers, Sam
Hi Sam; Thanks for the quick reply. I actually updated the wiflyinterface lib this morning - wondering why I missed that yesterday... unfortunately my Wifly now does not connect any more (no other changes). Will go back to Wifly_configure and check....and let you know. Thanks, Rolf
posted by 20 Dec 2012