TcpSocket with point to point

Hi everyone,
my question is simple: is it possible to establish a point to point connection with an STM32F767 using the EthernetInterface with Mbed OS 5.14? I’ve tried my code using the DHCP from my router and everything works. When I connect the board directly to my pc and setting the ethernet address manually I’m not able to connect with the TCP socket. What I’m missing?

My computer is configured with manual address:

  • IP 192.168.0.30/24

on the board, I’ve set the manual address to:

  • IP 192.168.0.45

  • NETMASK 255.255.255.0

  • GATEWAY (should not be necessary for point to point connection) but I’ve anyway tried to 192.168.0.1, 192.168.0.254, 192.168.0.30

      // creating the network interface
      EthernetInterface eth;
      eth.set_dhcp(false);
      int retval = eth.set_network(mbedIP.c_str(), mbedMask.c_str(), NULL);
      if(NSAPI_ERROR_OK != retval)
      {
          pc.put("Cannot configure the network: " + std::to_string(retval) + "\n");
      }
      else
      {
          // Show the network address
          pc.put("Connecting to the network...\n");
          retval = eth.connect();
          if (NSAPI_ERROR_OK != retval) {
              pc.put("Unable to create ethernet interface: " + std::to_string(retval) + "\n");
          } else {
              pc.put("Connected with ip: " + std::string(eth.get_ip_address()) + "\n");
              pc.put("netmask: " + std::string(eth.get_netmask()) + "\n");
              pc.put("gateway: " + std::string(eth.get_gateway()) + "\n");
    
          pc.put("Start creating the server\n");            
          TCPSocket server, *clt_sock;
          SocketAddress *clt_addr;
          
          retval = server.open(&eth);
          if (NSAPI_ERROR_OK != retval) {
              pc.put("Unable to open\n");
          }
          
          retval = server.bind(eth.get_ip_address(), 4100);
          if (NSAPI_ERROR_OK != retval) {
              pc.put("Unable to bind\n");
          }
    
          retval = server.listen(1);
          if (NSAPI_ERROR_OK != retval) {
              pc.put("Unable to listen\n");
          }
    
          while (true) {
              pc.put("Waiting for a client connection\n");
              clt_sock = server.accept(&retval);
              if (NSAPI_ERROR_OK != retval) {
                  pc.put("Unable to accept\n");
              }
              else {
                  clt_sock->getpeername(clt_addr);
                  pc.put("Accept: " + std::string(clt_addr->get_ip_address()) + " " + std::to_string(clt_addr->get_port()));
                  clt_sock->send("Hi", strlen("Hi"));
              }
          }
      }
    }

Hi there,

According to documentation of ethernet interface.

  • The eth.set_dhcp(false); is not need to set when you call eth.set_network(…);, because it will disable the DHCP automatically.
  • Both methods, from above, required be disconnected from a network during settings. I do not know where I saw that but I call eth.disconnect(); before it. I’m not sure if it still required, probably not but I still use it.

My personal points

  • For a direct connection with a PC you also need a cross ethernet cable.
  • The static IP can be set as alternative and not need to be as master, in the Windows.
  • You can check my TCP_EchoServer example. For your requirement you only need to set correct IP and take out ROUTER macro.

BR, Jan