Thing is that's exctly what I done before this approach. Here's a similar code that I tried, where I create an array of sessions and look for the first one that's available, and use that one to accept a new connection. I have exactly the same problem: First client connects well, we can communicate, I receive his messages and I can send him messages back.
Then, whenever a second client tries to connect it's automatically disconnected. Also, if i disconnect the first client and try to connect him back, he also can't connect anymore, gets instantly disconnected. Here's a log of what I mean: Connected: 0 //client "0" connects with netcat Received from 0 : a //client sends messages Received from 0 : b Received from 0 : c Connected: 1 //client "1" connects with netcat Disconnected: 1 //disconected immediately Disconnected: 0 //I close the connection of clent "0" Connected: 0 // I try to connect again with client "0" Disconnected: 0 //Same problem as client "1" Connected: 0 Disconnected: 0 Here's the current code: http://pastebin.com/1eQd9dzQ Mihai On Sun, Sep 20, 2015 at 2:05 PM, Pîrvu Mihai <[email protected]> wrote: > 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. > > The code I wrote is here: http://pastebin.com/zUuTtfL0 > > 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 >
_______________________________________________ lwip-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/lwip-users
