Page 1 of 1

wxSocketClient is killing me!

Posted: Wed Jun 22, 2005 5:37 pm
by alaricljs
Ok, I'm trying to open a socket connection and it's segfaulting. I have no idea why, there's no real indicators in the backtrace, I'm at a total loss. I think I have everything implemented that's necessary.

Below, wxString host is passed from a modal dialog with a wxTextCtrl as:
if (UI->DoConnect(text_address->GetValue())) {
The wxMessageBox does indeed show the right address, yay.
connection->Connect is the call that dies with a segfault. gdb doesn't drill into the Connect call, so it's got to be that connection doesn't exist (or something like that)

Code: Select all

bool UI::DoConnect(wxString host)
    wxIPV4address addr;
    //(void)wxMessageBox((addr.Hostname()).c_str(), _T("test"), wxICON_INFORMATION);
    connection->Connect(addr, false);
    if (connection->IsConnected())
        return true;
        return false;
This is the UI ctor section pertaining to the connection:

Code: Select all

    // Create the socket
    connection = new wxSocketClient();

    // Setup the event handler and subscribe to most events
    connection->SetEventHandler(*this, Socket_ID);
    connection->SetNotify(wxSOCKET_CONNECTION_FLAG |
                          wxSOCKET_INPUT_FLAG |
OnSocketEvent is a stub that does nothing with the events.

So why is connection->Connect() dying ??!?

Posted: Wed Jun 22, 2005 11:54 pm
by lowjoel
what address did you try to put into the connect function?

Posted: Thu Jun 23, 2005 4:48 am
by GianT
Maybe it's your host variable which causes this problem. Try passing the address yourself, like for localhost:

Code: Select all

It's not really a wxString, but this works in my program.

Posted: Thu Jun 23, 2005 2:30 pm
by alaricljs
Ok, the issue actually has nothing to do with the address. I've done the whole breakpoint/watch variable on my address section, it's picking up the address just fine.

It also has nothing to do with the ->Connect call, technically speaking. The issue is that in the UI::DoConnect() function any reference to connection segfaults because connection is apparently either not created or not pointing to the right place.

I have no idea why it would not exist (I create it in the ctor of UI:: ) and I see no reason for it to be pointing off into space.

Here is a link to a complete Dev-cpp project that is purely a demonstration of this issue. Please take a look.

Posted: Thu Jun 23, 2005 3:02 pm
by upCASE
Easy one :D

The problem is that "top" never is set to a correct value, thus you do call DoConnect() on some test instance, but not on the one you wanted...

Add a line like:

Code: Select all

top = (test*)parent;
as the last of ConnectDialog::ConnectDialog(wxWindow* parent) and it works charming.

BTW: I'd do it another way, but it's only opinion. Why not let the main frame call the dialog and test if it returned OK, then get the string from the dialog and connect?

Posted: Thu Jun 23, 2005 3:10 pm
by alaricljs
How very strange... I remember writing that line. And yet it's not there anymore... Hrm, probably some stupid Dev-cpp/wxGlade interaction where I didn't save my files before doing some UI changes in wxGlade...

Thanks for noticing, and the suggestions. I tried having the main frame call the connection dialog, but never figured out how to get it to work. Don't remember what I tried, but no UI ever got displayed the way I did.

Thanks again!

Posted: Thu Jun 23, 2005 3:20 pm
by alaricljs
Ok, it works wonderfully in my little demo project. I go back to the big project and implement the changes.... and I get a linker error! undefined reference to vtable ??

Any idea what this means? (If you haven't noticed I've never coded in C++ before ;) )

Posted: Thu Jun 23, 2005 3:35 pm
by alaricljs
Ok, my own editing stupidity but that's an awful weird error for what I did. I had a dtor defined in the class, and had no dtor function code. Yay.