LWIP- mulitple client example

sukeshak
Posts: 49
Joined: Sat Aug 19, 2017 10:20 am

Re: LWIP- mulitple client example

Postby sukeshak » Wed Sep 20, 2017 11:03 pm

Thank you for the response. Will run through some tutorials soon.

I changed the loop as well... since it makes better sense :)

sarpdaltaban
Posts: 4
Joined: Fri May 25, 2018 9:01 am

Re: LWIP- mulitple client example

Postby sarpdaltaban » Fri May 25, 2018 9:08 am

Dear members,

I am new to the forum and I am planning to implement a multi client LWIP server without RTOS.

Mr. Kolban defines an outline for threading as:

int s = socket();
bind(s, port);
listen(backlog);
while(true) {
int newClient = accept(s);
createTaskToHandleClient(newClient);
}

What about without threading?

Kind Regards

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: LWIP- mulitple client example

Postby ESP_Sprite » Sat May 26, 2018 3:59 am

To be somewhat nitpicky: you'd still use the RTOS as the socket layer and the WiFi stack are depending on it. But if you're asking on how to do this without creating tasks for each client: you'd use something like select() to block until there's activity on any of the clients, then handle them appropriately when the select()-call returns.

rsamanez
Posts: 1
Joined: Fri Dec 09, 2022 4:01 am

Re: LWIP- mulitple client example

Postby rsamanez » Fri Dec 09, 2022 4:06 am

#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
#include <WiFi.h>

const char* ssid = "[YOUR-NETWORK-SSID]";
const char* password = "[YOUR-SSID-PASSWORD]";

void TaskClientSocket( void *pvParameters );

WiFiServer wifiServer(80);

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid,password);
Serial.println("Connecting to Wifi...");
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print(".");
}
Serial.println("Connected to WiFi network");
Serial.println(WiFi.localIP());

wifiServer.begin();
}

void loop() {
WiFiClient client = wifiServer.available();
if( client){
Serial.println("New Client Connected...");
xTaskCreatePinnedToCore(
TaskClientSocket
, "TaskClientSocket"
, 4098
, &client
, 2
, NULL
, ARDUINO_RUNNING_CORE);
}
}

void TaskClientSocket( void *pvParameters )
{
WiFiClient clientHandle = *((WiFiClient*)pvParameters);
for (;;)
{
while(clientHandle.connected()){
while(clientHandle.available()>0){
char c = clientHandle.read();
clientHandle.write(c);
}
vTaskDelay(100);
}
clientHandle.stop();
Serial.println("Client disconnected");
vTaskDelete(NULL);
}
}

Who is online

Users browsing this forum: Baidu [Spider], ESP_Roland, ESP_rrtandler and 123 guests