When exactly are sockets opened (occupied) -Ethernet W5100 based shield

Hi all,

My application runs on an arduino Mega and an ethernet W5100 based shield.

The following modules / functions are implemented :

Telnet Server
Web server
FTP client
UDP server/client
NTP RTC sync
modbus tcp client

I know its a lot to have on a single system :slight_smile:

I know that the W5100 chip can support upto a total of 4 concurrent sockets.

Therefore, not all of the above functions can run at the same time.
For example when FTP service is required which needs 2 sockets, Telnet is terminated to free-up sockets.

Web server and UDP is always available and Telnet is always listening for incoming connections.
Modbus tcp is periodically polling a remote modbus server and closes the connection after each poll

My problem arises when I try to also use NTP sync which employs UDP transmission: even with no Telnet or FTP connections, NTP sync fails.

How can I make sure that a socket is freed up?
Doesnt this client.stop() free a used socket ?
Is it possible to also stop a server?

Any other ways to get around this?

Doesnt this client.stop() free a used socket ?

It does, but not immediately. Before calling client.stop(), you should read ALL of the data that the server sent in response to the client request. Then, the socket will close immediately, as there is no pending data. There will be no need to call client.stop().

Is it possible to also stop a server?

The server that the Arduino is running? Or some server that the Arduino connects to?

The server that the Arduino is running? Or some server that the Arduino connects to?

The server that arduino is running of course in order to free up a socket. E.g webserver

Watcher: The server that arduino is running of course in order to free up a socket. E.g webserver

Does the server actually use a socket? I don't think it does. Clients connecting to the server use sockets, when they connect.

PaulS:
Does the server actually use a socket? I don’t think it does. Clients connecting to the server use sockets, when they connect.

those are not real sockets what is limited. only an array of states in Ethernet.h. the implementation looks suspicious to me, but I didn’t examine it deeper. and other networking libraries authors copy-pasted it