Go Down

Topic: Ethernet library Client id (Read 599 times) previous topic - next topic

Hello,
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?
Thanks.

Alberto

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");
    printPrompt();
  } 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!");
      badclient.stop();
    }
  }

  // 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
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278686415
modified version.
After the first client connect the other clients recive the too many connections message.
Bye.

Alberto

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy