Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / wxSocketBase & seperate class

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. wxSocketBase & seperate class
#3304
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

------------------------
Website: www.KaReLs0ft.be
Message2. Re: wxSocketBase & seperate class
#3320
Posted by: upCASE 2004-02-06 22:19:37
Hi!
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?

upCASE
-----------------------------------
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
#3324
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

------------------------
Website: www.KaReLs0ft.be
Message4. Re: wxSocketBase & seperate class
#3331
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 |
                    wxSOCKET_LOST_FLAG);
  m_sock->Notify(TRUE);

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

  m_sock->Connect(addr, FALSE);
  m_sock->WaitOnConnect(10);
==> 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?

------------------------
Website: www.KaReLs0ft.be
Message5. Re: wxSocketBase & seperate class
#4350
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 • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2024-3-29  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0