-->
Page 2 of 3

Re: ESP8266WiFi server.available() disconnects the client

PostPosted: Tue May 12, 2015 10:11 am
by martinayotte
Hi Ivan,
I've posted this thread more than 3 weeks ago, but nobody commented.
viewtopic.php?f=32&t=2612
Can you share you solution about Multiple Client TCPServer ?

Re: ESP8266WiFi server.available() disconnects the client

PostPosted: Tue May 12, 2015 11:19 am
by Lord Ivanhoe
Of course, here it goes.

first declare the number of clients you wish to deal with:
Code: Select all#define numOfClients 4
WiFiClient clients[numOfClients];


And then in your loop{}

Code: Select all   
for (int i = 0; i <numOfClients-1; i++)
   {
      if (clients[i]) {
         if (clients[i].status() == CLOSED) {
            clients[i].stop();
         }
         if (clients[i].available()) {

            //do what you want with this client's  incoming data here

            clients[i].flush();
         }

      }
      else {
         clients[i] = server.available();
      }
   }


And thats about it. It works like a charm. Altho server.print() is not implemented yet AFAIK, so you should just make your own. Basically just loop through all clients and if they are connected, do a clients[i].println("your message"). That should do the trick.

I hope this helps :)

Ivan

Re: ESP8266WiFi server.available() disconnects the client

PostPosted: Tue May 12, 2015 2:08 pm
by martinayotte
HI Ivan,

I was looking about an implementation with threads, but that's Ok, I will do something similar in the main loop().

Thanks for your help !

Re: ESP8266WiFi server.available() disconnects the client

PostPosted: Mon Jun 18, 2018 7:42 am
by dingodudesir
Ivan,

Could you please share the method of doing multiple-client server? I've been stuck on it for days and could use some help.

Thanks in advance.