Hello guys, I'm sorry if this was posted before, but i couldn't find an answer, so I'm gonna post here in search of one.
I want to create a simple multi-threaded TCP server, that handled each new connection on a separate thread. The listener thread will listen on the "main" thread, and every connection will create a new thread, that will communicate with the session created.
I have dug a little into the lwip API to see how netconn_accept works and I saw that it blocks until the "not_empty" semaphore frm the "acceptbox" mailbox has something in it.
Now, every time this happens, I create a new thread and the session creation is done there, and I block the main thread using the "semaphore" variable, so a new connection doesn't happen while I still proces the old one.
Now, the problem is pretty much this:
- I connect the first client, it works just fine
- When ANY second client tries to join, it automatically gets disconnected and the server's console prints: Disconnected: 1, so netconn_recv doesn't return ERR_OK.
So my question is:
- How can I create this multi-threaded enviroment so each client is processed in a different thread?
- Also, what am I doing wrong in my current setup ?
PS: The application runs on Linux atm, using lwip 1.4.0 (last stable one), the unix port from contrib directory and the clients connect using netcat <ip> <port>.
Mihai