Go Down

Topic: Ethernet library Client id (Read 1 time) previous topic - next topic


i try to write a telnet server for arduino's ethernet shield, i find some really god code on internet, but all soffer from a problem:
you don't know from which client you are reciving data, and cannot reassemble command in variable.
This little modification in the Ethernet lybrary resolve the issue.

Client.h in public
uint8_t id();

Client.cpp at the end
uint8_t Client::id () {
   return _sock;

with this function you can understand from wich client you are reciving data, and have four different sessions from 0 to 3.
Do you think this code is good?
There are other methods for understand which client is sending data whithout the need of adding a function?



It work, here

   before void setup()

  int clientID; 
  Client badclient = 0;

the new loop()

void loop()
  // look to see if a new connection is created,
  // print welcome message, set connected flag
  if (server.available() && !connectFlag) {
    connectFlag = 1;
    client = server.available();
    clientID = client.id();
    client.println("\nSteve's Arduino Telnet Server");
    client.println("? for help");
  } else if (server.available()) {
    badclient = server.available();
    int tempid = badclient.id();
    if ( tempid != clientID) {
      badclient.println("\nSteve's Arduino Telnet Server");
      badclient.println("Sorry, only one client at time allowed!");

  // check to see if text received
  if (client.connected() && client.available()) getReceivedText();

  // check to see if connection has timed out
  if(connectFlag) checkConnectionTimeout();

// code to do other things in loop would go here


of the tenet server
modified version.
After the first client connect the other clients recive the too many connections message.


Go Up