-1

I've currently coded a server/client implementation in C++, where two clients connect to a server. I'm expecting from previous experience (I'm new to C++) that each client (and the server) will have an event handler, and events will come in when either the client wants to send a message to the server, or the client has received a message from the server. You can view it as a chat server; the 'outgoing' event from the client could be the triggered by the user typing something in the console, and the 'incoming' event could be triggered by receiving data from the server.

Is there a standard way of coding this in C++? I'd ideally like to register callback functions for each possible event type, and for the callback function registered to be passed back as a context to the event handler when each event is received, so I can process each event in its specific handling function. And of course once the event has been handled, I want my program to fall back into its event loop.

Any ideas? I'm very comfortable with the event-driven style of programming so would prefer to keep it this way if possible rather than learning entirely new paradigms.

Simba K
  • 9
  • 1

1 Answers1

0

C++ does not have a built-in event handler system (unlike, say, C# and delegates) but there exists plenty of libraries to do that. libsigc++ is one of them.

As a result, any library you use for networking will also have to provide event handling code, either their own or using another library. And if you're rolling out your own networking code, I honestly think creating your own event handling code isn't all that difficult, but I might be insane.

Altainia
  • 1,347
  • 1
  • 7
  • 11