Buffered Ethernet Server library

The Buffered Ethernet Server library is meant to support a server that accepts requests and sends a response to the clients. It has been developed for the original Arduino Ethernet Shield with the WIZnet W5100 chip. Extensive tests were made using the Arduino Mega 2560 R3 and the PC browsers Firefox and Opera.

For the moment, only strings can be sent (may be sufficient for http).

A special feature is that the server application can bring simple strings on the way to be sent without caring for buffering or for an efficient protocol on the network. The strings are accumulated in the send buffer of the W5100 chip. The library automatically sends the SEND command to the W5100 whenever buffer limits are reached. However the server application still has to issue a send command explicitly at the end of a request-response cycle to send the remaining content of the W5100's buffer.

The traffic to the client is relatively fast because the TCP window size of 2048 (sent over the line by the W5100) is used in two consecutive transmissions. The filled TCP window is immediately acknowledged by the client.

The download? No idea where to place the zip file.

Functional Overview

/*
Server initialization
The MAC address is required to address the station in the (physical) Ethernet network. The Ethernet shield for Arduino has a label with its MAC address underneath.
The IP address is required in the (logical) network layer above the physical network. The IP address will be dependent on your local network.
*/

  int startServer(byte *ipAddress, byte *macAddress);

/*
Probes the four sockets of the W5100 for a request waiting for an answer. A request without a text is ignored.
Closed sockets are brought back on the listening track.
*/

  int getNumberOfASocketWithARequest();

/*
Received data is transferred out of W5100's internal memory into the application's buffer.
lengthOfBuffer is most important to avoid a buffer overflow, writing over other data.
If there is more data received than the buffer can hold, the received data is truncated at the end of the buffer. The given buffer length is respected.
*/

  int getClientRequest(char *bufferForReceivedData, int lengthOfBuffer, int socketIndex);

/*
Adds the given null-terminated string to the string that is buffered in the W5100 for sending.
Whenever the gathered data reaches buffer limits, the W5100's buffer is freed by sending the accumulated string to the remote partner who is in session with the given socket.
*/

  int addStringToSend(char *dataToSend, int socketIndex);

/*
The send command tells the W5100 to send its buffered data to the remote station.
*/

  int send(int socketIndex);

/*
Returns the IP address of the remote partner in an array of 4 bytes.
*/

  void getRemoteIpV4Address(byte *remoteIpV4Address, int socketIndex);

/*
Returns the remote partner's port number that is in session with the given socket.
*/

  int getRemotePortNumber(int socketIndex);

/*
Delivers the IP address of this machine in an array of 4 bytes.
*/

  void getLocalIpV4Address(byte *localIpV4Address);

/*
The TCP session is closed.
*/

  void disconnect(int socketIndex);

Using the Library

This will follow after the download will be possible.

Share