Pages: [1]   Go Down
Author Topic: Ethernet library Client id  (Read 507 times)
0 Members and 1 Guest are viewing this topic.
Milan, Italy
Offline Offline
Sr. Member
****
Karma: 0
Posts: 332
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Milan, Italy
Offline Offline
Sr. Member
****
Karma: 0
Posts: 332
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Pages: [1]   Go Up
Jump to: