Connecting multiple clients by ethernetshield

Hello all,

I made a ethernet server class, where (multiple) clients can connect to.
But when I have a special message (say an analog output value) for one of the clients, how do I have to send that message to that particular client?


If my memory isn’t wrong, some guy has alreayd post a mean to get the remote IP of the connecting client. You can have a search in this forum. But the Ethernet library doesn’t provide this interface directly. If you know the remote IP, you can distinguish the user.

Hope it helps.

I copied this from the chap mentioned above … i think. It works for me.

          client.println("Your IP is:");
          for (int n = 0; n<=3; n++)

just need to add the following in your declarations section .

byte client_ip[4];

good luck


thank you for the info on how to get the IP address, at least this is working, and I'm a step further now.
But how to solve 2 clients on the same computer connected to my arduino server? I'm getting 2 times the IP address ;-(


You need read more regarding how the full-functional web server handles the Sessions. You can use the similar mean.

I'm not sure if it works that using the remote IP + port to distinguish the different user on the same machine. Different clients will use differet ports. What isn't clear to me is if the same client will use the different ports during a session.


Hello Jefrey,

it is not a webserver, but a normal tcp-server, with a special message protocol (called SIOC, used by flightsimulation)
my tcpserver is listening at port 8092, and several clients can connect to it, to send or receive info from the arduino IO.

when my knowledge of tcp is right, I think the client connects to the server at port 8092, but is sends an unique portnumber on where the server can send the info back to the client.
so when I can detect that specific portnumber, I can uniquely idtentify every connected client.

still another question, is it possible to detect if a client still is connected to the server or has lost the connection with the server or disconnected from the server?


I'm using Arduino as a web server. I can use the IE browser to request the web page from it. Obviously, my PC and Arduino communicate with http protocol.

I use the Analyer (protocol tool) to capture all http packages throgh my network card. I find that the TCP port at the PC side changes for different http request. In my case, the TCP port of the first http request from PC to Arduino is 2996, that for the next is 2997. Note: the IE page isn't closed during the two requests, it just sends different http POST requests to Arduino. (I capture a snapshot. I don't how to add image to the forum. Does anybody know?)

That means if use the IE browser to connect the Arduino, the TCP port will be changed for different TCP connection. At Arduino side, you can't use the remote TCP port to identify a client. (The same client uses different ports)

For my web server code running on Arduino, I will call the function client.stop() when a http response is finished. This function will disconnect the TCP connection. I think that's why the TCP port at PC side changes.

Unless you write the code of PC application yourself and specify both the local and remote ports of the TCP socket. Then you can keep the TCP port at PC side unchanged when reconnect to Arduino again.

To check whether the connection between the client and server is live, maybe you using the means of heartbeat detection or watch dog. The client sends data to server periodically. If the server can't receive data from client after a specific time, we can suppose the link is disconnected. I don't know anyother better method.

it is not a webserver, but a normal tcp-server, with a special message protocol (called SIOC, used by flightsimulation)
my tcpserver is listening at port 8092, and several clients can connect to it, to send or receive info from the arduino IO.

Even though you are using a different protocol, my analysis to the http protocol are also the same to it. They are all based on the TCP protocol, and what we are discussing is to use the TCP header data to distinguish the remote clients.


thank you for your explanation.
Then I first skip the idea for several clients on 1 IP address for now.
The client I work with now is an third party app, so I don't have no influence on it (or at least almost no influence)

about checking if the client is alive, I thought is was possible to check if there is some socket state I can check in the Client.cpp (or W5100.cpp)
because the client software is third party, and the protocol does not realy requires sending data after a specific time. (only data when there need to be something changed, or when there has something changed)


You can have a try.

Reading the code in w5100.h, you can find the max socket number is 4, which is defined by the macro MAX_SOCK_NUM. If you keep the TCP connection, that means the client number is very limited, unless 4 clients are enough for you.

#define MAX_SOCK_NUM 4

I've already seen MAX_SOCK_NUM.
do you think I can change that variable?

but probably 4 is enough for me.

The point is that the client(s) have to stay connected, because I have to send at several moments some info back to the client, so you cannot compare it with a html client, where the html client request or send some data, and waits for the result, and then is finished.

the client sofware I use has to be connected during the whole process.

Short explanation of what I'm doing:
I'm building a full-scale Boeing 737NG simulator, and the part I'm building at the moment is the throttle unit (2 throttle levers, 2 trust-reverser, flaps handle, speedbrake handle, parking brake, and some more)
The client software is from prosim737 and it connecting via tcp and the SIOC protocol, so I'm stuck with that (and that is normaly no problem when using 2 pc's)
So when I say for example change the flaps-setting by moving the flaps-handle, the prosim software has to be informed by the new value.