7 years, 4 months ago.

Checking ethernet and socket connection on mbed-os 5

I am running mbed-os 5 on a STM32F746G-DISCO discovery board.

When running a TCP server what is a good way to check periodically if the ethernet and socket connection (to client) are still good? Any recommended methods to re-establish connection if they are dropped?

2 Answers

6 years, 8 months ago.

Hello,

I have the exact same question. Cyriac, did you made any progress or find anything in the current documentation related to that?

6 years, 8 months ago.

You can check what returns sent function. If it is positive number your connection is good. If it is negative number check with Network Error list.

https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/

If you got negative return according to specific error you should reinitialize or change settings of your network. Cannot explain more accurate, need more detail what you trying to do with TCP server.

Daniel

Thank you for your answer, I am still discovering the network API. My understanding is that both send or recv are blocking which means that I cannot test the connection without being blocked if it is still up, no? Is there a non-blocking API?

posted by G autaz 29 Aug 2017

Can you explain what your program exactly does? What Operating system you using? Dev board? What do you mean by recv or sent are blocking what?

I can guess: 1. If using windows check if no conflict with IP or port already in use, also Firewall could block messages. 2. If you save return value of function sent() or recv(), you can printf after function has been completed. Example: int ret = sent(IP, port, etc.) or recv(IP,port, etc.) printf(ret)

posted by Daniel Klioc 29 Aug 2017