Guidance Forums / wxWidgets (wxWindows) in C++ / wxSocketBase & seperate class

Search 搜索
Home Home

Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxSocketBase & seperate class
Posted by: KaReL 2004-02-03 00:28:42
I want a socket in a seperate class...
-- easy : wxSocketBase * m_sock & all the new/deletes

But I want this socket to receive events too...
And that is the difficult part...

How can I get this socket to receive events?

2nd question: When shall i initiate (start) the connection? As I already tried deriving my class from wxEvtHandler, and starting my connection in MyApp->OnInit(); But it didn't worked out ...
At the moment it only works when the main frame has been drawn and I push a button to start the connection...

wxWindows: CVS_HEAD
OS:        Windows2000/4
IDE:       MS Visual 6/5

Message2. Re: wxSocketBase & seperate class
Posted by: upCASE 2004-02-06 22:19:37
The major question is: Is your class derived from a wx class that supports event handling (like wxControl or wxWindow) or not. Since the event handling troubles you and since your mentioned "wxSocketBase... in another class", I guess you didn't derive the class from anything (at least not from wxWindow).
There still is a way to manage this, although I must confess that I myself just found out about it and didn't know that this was possible :) Had a similar problem here while hacking up the basic parts of my res editor and managing stuff like selection of one object at a time. Guess I'll have to rework that part though :)
Have your tried deriving your class from wxEvtHandler and use Connect() on itself?

If it was hard to write, it should be hard to read!- Do. Or do not. There is no try!
Message3. Re: wxSocketBase & seperate class
Posted by: KaReL 2004-02-07 03:43:20
my class is just something totally different (no parents whatsoever).

I tried deriving it, but not to "connect" itself...

I will look into that after a night of sleep

Message4. Re: wxSocketBase & seperate class
Posted by: KaReL 2004-02-08 05:41:37
  Connect( SOCKET_ID, wxEVT_SOCKET, (wxObjectEventFunction) (wxEventFunction) (wxSocketEventFunction) CIRC_Server::OnSocketEvent );

  m_sock = new wxSocketClient();
  // Setup the event handler and subscribe to most events
  m_sock->SetEventHandler(*this, SOCKET_ID);
  m_sock->SetNotify(wxSOCKET_CONNECTION_FLAG |
                    wxSOCKET_INPUT_FLAG |

  wxIPV4address addr;
  addr.Hostname( server );
  addr.Service (  port  );

  m_sock->Connect(addr, FALSE);
==> Just waits there, but I asked my friend who was running the test-server, and he saw a connection from me... But the event never got through to me?

Message5. Re: wxSocketBase & seperate class
Posted by: 2004-06-06 00:01:39
I have exactly the same problem.. I seem to connect to the server, but the server never gets the socket event for connection. Have you solved your problem? if so how? thx..
Forum List • Thread List • Refresh • New Topic • Search • Previous • Next First 1 Last
© Mon 2024-6-17  Guidance Laboratory Inc. Hits:0