mattgodbolt / seasocks

Simple, small, C++ embeddable webserver with WebSockets support
BSD 2-Clause "Simplified" License
724 stars 120 forks source link

Serve multiple ports? #135

Open cspain opened 4 years ago

cspain commented 4 years ago

Hey guys,

It is possible for Seasocks to listen and open multiple connections on more than one port? I am thinking of a scenario where we have, say a data channel on port 1234 and control channel on port 5678.

One way I thought of doing this is creating two server objects (one per channel) and having each do server.serve() on its own thread. The parent of these two threads could send data out using server.execute(connection->send) on each server object?

Is there a better way where I can call listen() and handle simultaneous connections on more than one port?

Thanks for creating a great tool!

-Chris

hoytech commented 4 years ago

I haven't looked in detail, but I think the thread-per-listener approach is probably your best option. Hooking into the event loop isn't very easy (ie requires code modification) as we discussed a bit in #47 .