Evan DeMond | 7 Oct 07:34

Handling socket events?

Hi all,

I'm writing a wxLua app which needs socket functionality, and I'm having trouble figuring out how to handle events from wxSocketClient. wxSocketBase doesn't inherit from wxEvtHandler, meaning Connect() isn't an option. I went looking and found this:

http://docs.wxwidgets.org/stable/wx_wxsocketbase.html#socketevents
http://docs.wxwidgets.org/stable/wx_wxsocketbase.html#wxsocketbaseseteventhandler

So I tried to set up a plain wxEvtHandler object, hooking it up to the wxSocketClient with SetEventHandler(), and trying to Connect() the wxEvtHandler to wxSOCKET_INPUT - but that apparently fails?

"Lua: Error while running chunk
...
wxLua: Invalid or unknown wxEventType for wxEvtHandler::Connect() : 0, winIds -1, -1."

I can't seem to find any example code using wxSocketClient in Lua anywhere. All the C++ code I've seen uses the EVT_SOCKET macro, but that's not available in pure Lua.

I'm stumped. How does one receive wxSocketClient events in a wxLua program?

Thanks,

Evan
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
wxlua-users mailing list
wxlua-users@...
https://lists.sourceforge.net/lists/listinfo/wxlua-users
John Labenski | 7 Oct 16:50

Re: Handling socket events?

On Tue, Oct 7, 2008 at 1:35 AM, Evan DeMond <evan.demond@...> wrote:
> Hi all,
>
> I'm writing a wxLua app which needs socket functionality, and I'm having
> trouble figuring out how to handle events from wxSocketClient. wxSocketBase
> doesn't inherit from wxEvtHandler, meaning Connect() isn't an option. I went
> looking and found this:
>
> http://docs.wxwidgets.org/stable/wx_wxsocketbase.html#socketevents
> http://docs.wxwidgets.org/stable/wx_wxsocketbase.html#wxsocketbaseseteventhandler
>
> So I tried to set up a plain wxEvtHandler object, hooking it up to the
> wxSocketClient with SetEventHandler(), and trying to Connect() the
> wxEvtHandler to wxSOCKET_INPUT - but that apparently fails?

wxSOCKET_INPUT is an enum wxSocketNotify, an integer with a value of
0, not an event type.

> "Lua: Error while running chunk
> ...
> wxLua: Invalid or unknown wxEventType for wxEvtHandler::Connect() : 0,
> winIds -1, -1."
>
> I can't seem to find any example code using wxSocketClient in Lua anywhere.
> All the C++ code I've seen uses the EVT_SOCKET macro, but that's not
> available in pure Lua.

The EVT_XXX() are C_++ macros that statically connect events at
compile time, so wxLua cannot use them, instead we use the dynamic
events and the wxEvtHandler::Connect() function.

The mapping between the EVT_XXX() macros and the dynamic event types
are described in the doc below. Search for EVT_SOCKET and you'll see
that you want to use wxEVT_SOCKET and that you will get a
wxSocketEvent object in your callback function. Note that the names
aren't always so easy to guess.

http://wxlua.sourceforge.net/docs/wxluaref.html

You can use any wxEvtHandler derived class you want, typically people
will use their wxFrame or a wxWindow that they already have.

Hope this helps,
     John

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
Evan DeMond | 7 Oct 17:15

Re: Handling socket events?

On Tue, Oct 7, 2008 at 10:50 AM, John Labenski <jlabenski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

wxSOCKET_INPUT is an enum wxSocketNotify, an integer with a value of
0, not an event type.

Aha - I think the docs were throwing me off the trail on that point, as wxSOCKET_INPUT is listed in a table under "wxSocket Events". I thought they would be on par with other event types.

The mapping between the EVT_XXX() macros and the dynamic event types
are described in the doc below. Search for EVT_SOCKET and you'll see
that you want to use wxEVT_SOCKET and that you will get a
wxSocketEvent object in your callback function. Note that the names
aren't always so easy to guess.

In the wxLua reference I had found the line

%define_event wxEVT_SOCKET // EVT_SOCKET(id, func)

...but didn't know what it meant. So the approach, then, is to do something like this?

sock:SetEventHandler(someHandler, wxEVT_SOCKET)
someHandler:Connect(wxEVT_SOCKET, function (ev) if ev == wxSOCKET_INPUT then ... end)

Hope this helps,
    John

Thank you, it definitely does - I'll try it out tonight and post back if I run into any roadblocks.

Evan

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
wxlua-users mailing list
wxlua-users@...
https://lists.sourceforge.net/lists/listinfo/wxlua-users
Evan DeMond | 7 Oct 17:17

Re: Handling socket events?

...but didn't know what it meant. So the approach, then, is to do something like this?

sock:SetEventHandler(someHandler, wxEVT_SOCKET)
someHandler:Connect(wxEVT_SOCKET, function (ev) if ev == wxSOCKET_INPUT then ... end)

Oops, I meant if ev.GetSocketEvent() == wxSOCKET_INPUT, of course

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
wxlua-users mailing list
wxlua-users@...
https://lists.sourceforge.net/lists/listinfo/wxlua-users

Gmane