How to distinguish between clients communicating via ethernet

Hi all,
Finally with all help from forum and from comments of my previous posts ,
I Could establish communication between:

  1. 2 arduino Due using ethernet switch (bi directional communication)
  2. 1 arduino and laptop again using same switch. (bi directional communication)
    Thanks to all.

But my next issue where I am stuck is:

I have 3 arduino due, 1 of which is server and 2 other to be clients.
I am able to assign unique ip and mac address to each arduino.
Some of the commands I know on server side is

IPAddress ip(192, 168, 1, 177);
EthernetServer server(23);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
EthernetClient client = server.available();
client.parseInt(); (to receive an integer)

Some of the commands on Client side

IPAddress server(192,168,1,177);
Ethernet.begin(mac, ip, gateway, subnet);
client.connect(Server,23);
client.println("something here");

Now the questions are:

  1. How would server know which client got connected ?
  2. Can both clients be connected together to server ? Of course the data receiving at server will be sequentially but can all 3 arduino be stay connected all the time ? (i.e. I don't need to do again and again client.connect etc ?
  3. Also if 2 clients are simultaneously sending client.println command then how to receive both the information on server arduino and how to differentiate them that which one sent which command ?

Send a client name or number with each send.

SurferTim:
Send a client name or number with each send.

So what I interpret is, when I do client.println(), I will send first the name or number I am assigning to each client and then receive data ? Am I correct ?

Can't the data and number be sent in one go or something ? (I mean is there any specific command I am missing). The reason being, say i sent the client number, what if other client sent data before this client. Then at the receiving end it will be like, client number of one client but data of other.

I want something like for e.g.
When we do I2C communication using Wire library. We specifically can mention that receive data from this client and this many bytes , so there is no problem of mismatching.

Wire.requestFrom(2, 6);

I want something similar in ethernet but of course it could be in different form. Or even if there is any other way that would be helpful.

Thanks in advance.

Use something like this:

client.connect(Server,23);
client.println("12345,something here");

Change "12345" to unique numbers for each client.

SurferTim:
Use something like this:

client.connect(Server,23);

client.println("12345,something here");



Change "12345" to unique numbers for each client.

ok. Thanks. Will try that out and update back soon.

SurferTim:
Use something like this:

client.connect(Server,23);

client.println("12345,something here");



Change "12345" to unique numbers for each client.

Hey,
I get that this is one of the method that I can use to distinguish clients.

But just the general thought, isn't in the communication protocol when the packet is send (it has Data as well Ip address assigned to it while it is sent).
If so, isn't there would be a way to extract the ipadress of the client , the data is coming from ?
Isn't this the basic thing of communication protocol ?
Please correct me if I am wrong.

If the client network settings are static, that would be good. If they might change (like dhcp), it isn't good.

With the method I suggested, I can connect the clients to any network and the server can identify each client.

SurferTim:
If the client network settings are static, that would be good. If they might change (like dhcp), it isn't good.

With the method I suggested, I can connect the clients to any network and the server can identify each client.

The client network settings are static indeed. Because I am setting them to be static. But as I mentioned in previous post, it would have been great if there was way to extract IP address from the incoming client. The example you show is with if you are passing some message. Say if i am passing some variable , so it would be

1) client.println("12345");
2) client.println(answer);

There is high chance that between step 1 and step 2, another client might interfere.
Another example is in UDP we have this

IPAddress remote = Udp.remoteIP();

So I was searching if there is something similar in our case ?

swaroop2011:

1) client.println("12345");
  1. client.println(answer);


There is high chance that between step 1 and step 2, another client might interfere.

There is no chance another client will interfere.

There is no way to get the IP of the incoming client without modifying the library code or using a low level function.

SurferTim:
There is no chance another client will interfere.

There is no way to get the IP of the incoming client without modifying the library code or using a low level function.

Ok. Got it. Thanks a lot.
I guess once the client gets connected only his data will be collected. So I believe the race would be which client gets connected first. Am I right ?. If yes, then I might have to think on how to make each client connect once and in sequence or so. Please let me know if I am going wrong ?.
May I Please know what exactly you meant by "using a low level function" ?
I know that High level contains data being transmitted and low level contains address information. But to write that function , how to go about it ? Can you provide with some documentation or any link which will be helpful.

swaroop2011:
I guess once the client gets connected only his data will be collected. So I believe the race would be which client gets connected first. Am I right ?. If yes, then I might have to think on how to make each client connect once and in sequence or so.

Yes. That socket will communicate with only that one client as long as that client is connected.

You can use the w5100 part of the library to retrieve the IP of the client. I modified the library to get that data in earlier IDE versions, but haven't needed that feature lately.

SurferTim:
Yes. That socket will communicate with only that one client as long as that client is connected.

You can use the w5100 part of the library to retrieve the IP of the client. I modified the library to get that data in earlier IDE versions, but haven’t needed that feature lately.

ok Thanks. As mentioned in previous comment,
If I need to make each of the client get connected in sequence, what you think is the good way ? (I couldn’t come with some Idea, may be I am missing some pieces either in communication part or programming part ).
So that no client is missed.

Also when you mention modifying the w5100 part of library. Can you please provide few steps of which library to access and any direction about what syntax or code is required to extract client IP ?

Thanks in advance.