Sockets FAQ/Tutorial

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Rhodes
In need of some credit
In need of some credit
Posts: 1
Joined: Sat May 15, 2021 7:37 pm

Re: Sockets FAQ/Tutorial

Post by Rhodes »

This post is pinned, but appears to be from over 15 years ago. Is the information still relevant?

I am fairly new to wxwidgets programming, however I have done a significiant amount with GUIs in the past.

I'm confused by events in wxwigets. There are event tables, functions like Connect and also Bind. I understand that event tables are an old way of doing things: Setting events up statically at compile time, and that Connect is dynamic, and newer, but that Bind is newer still and is now the prefered way to handle events.

With sockets, there also appear to be a further function: SetEventHandler().

So am I to use a combination of SetEventHandler and Bind? I don't understand why SetEventHandler is neccessary. It appears to be a member function of either the client or server socket, and takes as argument an EventHandler, of which the wxWindow is a derived class.

The arguments to Bind also appear to be very strange. It takes a few arguments, one of which is the address of the callback function, but NONE of which are a server or client socket structure.

Even weirder are that some graphical user interface objects inherit from wxWindow, but this is a tangent at this point.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Sockets FAQ/Tutorial

Post by doublemax »

This post is pinned, but appears to be from over 15 years ago. Is the information still relevant?
Honestly, i don't know. I'd use the "sockets" sample that comes with wxWidgets as reference.
I'm confused by events in wxwigets. There are event tables, functions like Connect and also Bind. I understand that event tables are an old way of doing things: Setting events up statically at compile time, and that Connect is dynamic, and newer, but that Bind is newer still and is now the prefered way to handle events.
This is all correct. Although i personally think it's still ok to use static event tables. Bind() does the same as Connect(), but it has additional typesafety at compile time that avoid mistakes that often lead to crashes when using Connect(). For that reason Connect() should be avoided.
With sockets, there also appear to be a further function: SetEventHandler().
Usually, with GUI events, the window is the natural event handler. But with sockets, it's unclear where socket events get sent to. That's why you need to call SetEventHandler()
Use the source, Luke!
Post Reply