5 years, 9 months ago.

etc.connect(); seems to hang in most (but not all) situations

Hi, ive been stuck with this issue for a few days.

I am using an mbed lpc1768

For some reason the UDPSocket example (and the TCP ones for that matter) hang when the EthernetInterface::connect() method is called the programme hangs, even when using this example from the documentation:

https://os.mbed.com/docs/v5.9/reference/udpsocket.html

However, this code I made using bits coped of the internet does work:

working code

#include "rtos.h"
#include "mbed.h"
#include "EthernetInterface.h"
 
#define IP        "169.254.36.85"
#define NETMASK   "255.255.0.0"
#define GATEWAY   "192.168.0.1"
 
 
EthernetInterface eth;


int main()
{
    printf("TCP server example\n");
    
    eth.set_network(IP, NETMASK, GATEWAY);
    eth.connect();
    
    //udpThread.start(udpListen);
    udpListen();
    
    printf("The Server IP address is '%s'\n", eth.get_ip_address());
    
    TCPServer srv;
    TCPSocket client_sock;
    SocketAddress client_addr;
    char *buffer = new char[256];
    
    /* Open the server on ethernet stack */
    srv.open(&eth);
    
    /* Bind the HTTP port (TCP 80) to the server */
    srv.bind(eth.get_ip_address(), 32123);
    
    /* Can handle x simultaneous connections */
    srv.listen(1);
 
    srv.accept(&client_sock, &client_addr);
    printf("Accepted %s:%d\n", client_addr.get_ip_address(),client_addr.get_port());
    strcpy(buffer, "I am a string being sent to the TCP client \n\r");
    client_sock.send(buffer, strlen(buffer));
    printf("sent %s\n",buffer);
    
    while (true){
        for (int i=0; i<256; i++){
            buffer[i] = 0;
        }
        client_sock.recv(buffer, 256);
        printf("recieved %s\n",buffer);
    }
    
    client_sock.close();
    delete[] buffer;
}
 

As this works I don't think there is an issue with my wiring.

I have been stuck on this issue for a while so any ideas or pointers would be greatly appreciated.

Alright, so the issue was the MBED could connect to my PC but not my router, this was fixed by going to the network and sharing center, clicking devices and then bridging my WIFI and ethernet.

posted by Oran Deutsch 01 Aug 2018
Be the first to answer this question.