add operator==, remoteIP and remotePort to EthernetClient (please review)

EthernetServer doesn't provide any way to distinguish clients returned by Server.available() which makes it impossible to implement a Server that handles multiple long-lasting connections.

I added an operator == to allow this. It uses remote-port and remote-ip read from the W5100 socket-registers to differentiate (using just the _sock might lead to incorrectly returning true if a sockets became closed and reopend during compares).

also added remotePort and remoteIP

The updated ChatServer-example demonstrates the use of the ==-operator by distributing incomming messages to all clients but the one the message comes from. (The former ChatServer echos the messages back to the sending client).

find the code in my pull-request on github

(tried to post this to the developer-mailinglist on google , but for some reason it wouldn't show up. Is the developer-list moderated?)

Ciao Norbert,

just tested your changes and they work like a charme.
You did a great job, thanks.

These changes should help to make future server applications more comprehensible.

BTW, I had to change the includes (line 1 and 2) in the EthernetClient.cpp to compile the file:

#include "utility/w5100.h"
#include "utility/socket.h"

Running the 1.5.4 IDE on Win7

just updated the pull-request as I noticed the implementation of '==' was sematically equivalent to just comparing the _sock-index of socket-register.

Hi Norbert,

the line 106 of your example is, IMHO, redundant. The assignment of _sock = MAX_SOCK_NUM; is already done in the stop() method.

 clients[i]=EthernetClient();

CaptBlaubaer:
The assignment of _sock = MAX_SOCK_NUM; is already done in the stop() method.

thant’s a good point, thank’s a lot.

  • Norbert