smarques7 / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 1 forks source link

EthernetClient operator==() to allow for comparison of clients. #892

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What change would like to see?

In the EthernetClient is possible add a function for get the socket number?
Or if is not possible add a new function is possible expose the _sock variable 
to children classes?

Why?
Actualy if there are multiple connections open it is impossible know from wich 
client we are reciving data

Would this cause any incompatibilities with previous versions?
No.

In EthernetClient.cpp
uint8_t EthernetClient::getSocketNumber() {
    return _sock;
}

In In EthernetClient.h
uint8_t getSocketNumber ();

Thanks.

Alberto

Original issue reported on code.google.com by Alberto....@gmail.com on 20 Apr 2012 at 11:58

GoogleCodeExporter commented 9 years ago
To be more consistent with other sockets designs, shouldn't this be called 
getSocketHandle?

Thanks,
Gene

Original comment by Nightrad...@gmail.com on 25 Apr 2012 at 5:36

GoogleCodeExporter commented 9 years ago
Yes, the name is not important.
Thanks.

Alberto

Original comment by Alberto....@gmail.com on 25 Apr 2012 at 10:45

GoogleCodeExporter commented 9 years ago
I don't think it makes sense to add a function that returns the socket number, 
which is an implementation detail.  But adding an operator==(), so you could 
compare a previous client instance (from a previous Server.available()) to a 
new one could make sense.

Original comment by dmel...@gmail.com on 9 May 2012 at 12:58

GoogleCodeExporter commented 9 years ago
Yes, the important things is have a method for differentiate different client.
Thakhs.

Alberto

Original comment by Alberto....@gmail.com on 9 May 2012 at 8:10

GoogleCodeExporter commented 9 years ago
if you need to do any low level sock code them you need the socket number, not 
that the average Arduino user is going to be doing any/alot of sock code, but 
some may.

Gene 

Original comment by Nightrad...@gmail.com on 18 May 2012 at 5:49

GoogleCodeExporter commented 9 years ago
Most people don't write socket code, but most use ethernet library for receive 
data, and understand if we are receiving or sending data from a pre opened 
connection or from a new one is important for protocol that are not one shot, 
like http 1.0, but require multiple send / receive sequences like telnet server.

Alberto

Original comment by Alberto....@gmail.com on 22 May 2012 at 12:21

GoogleCodeExporter commented 9 years ago
I agree with Alberto, the main use case here is just telling if two clients are 
the same.  Again, an operator==() seems like the right way to handle that.  
Adrian, do you want to take a look at this?

Original comment by dmel...@gmail.com on 23 May 2012 at 2:52

GoogleCodeExporter commented 9 years ago
Hi, The other use case that I have a need for as well is to not just 
differentiate whether a client is different, but be able to track the client to 
be able to keep state information such as whether they have authenticated via 
their telnet connection etc.

From that point of view the socket number would be useful as it can then be 
used as an index for an array etc.

Can this please be taken into consideration when implementing the final 
solution?

Thanks!

Original comment by alwa...@gmail.com on 2 Jun 2012 at 3:09

GoogleCodeExporter commented 9 years ago
To clarify, the expectation in that use case would be that there could well be 
more than 1 client connected at a time (obviously up to 4).

Original comment by alwa...@gmail.com on 2 Jun 2012 at 3:11

GoogleCodeExporter commented 9 years ago
Hello,

I am trying to create a class that inherits from EthernetClient. I need to 
access the _sock and and _srcport variables. I have found that these variables 
are necessary when working with websockets. Perhaps you can make these 
variables protected instead of private, by making the following modification in 
the EtherClient.h file. This would allow people to inherit from the 
EthernetClient and create the the additional functions needed to access these 
variables.  

protected:
  static uint16_t _srcport;
  uint8_t _sock;

Thanks,

-ren

Original comment by rena...@yahoo.com on 3 Oct 2012 at 5:06

GoogleCodeExporter commented 9 years ago
Add pull request:
https://github.com/arduino/Arduino/pull/2844

Original comment by Alberto....@gmail.com on 30 Mar 2015 at 8:40