Pages: [1]   Go Down
Author Topic: Modify Client to allow IP address to be changed  (Read 393 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Due to the way the Arduino handles classes (ie a bit limited - can't use "new" to instantiate, for example), the existing implementation of the Client class has a problem.

I had a situation where I had a list of possible hosts, and I needed to connect to one of them - didn't matter which one. What I wanted to be able to do was try to connect to each in turn, and if a connection failed, to move onto the next in the list. To do this with the current implementation of Client means declaring a separate client for each connection, as it is impossible to change the IP address outside of the constructor.

I have therefore added a method to the Client class, as follows:

uint8_t Client::address(uint8_t *ip) {
  if (_sock != 255)
    return 0;
    
  _ip = ip;
  
  return 1;
}


This allows the IP at which the Client is targeted to be changed, as long as it isn't currently connected.

Is this a sensible addition to the Client class? If so, could it be added?
Logged

Pages: [1]   Go Up
Jump to: