WxWidgets - WxThread problem
Hi guys, I'm developing an application with that needs to have a permanent server socket in listening, so I put it in a thread, here there is the class I've written for it:
Code:
class listenThread : public wxThread
{
public:
listenThread(MyFrame *h) : wxThread() { handler = h; };
virtual void * Entry();
private:
MyFrame *handler;
};
void *
listenThread::Entry()
{
handler->sockConvs[nconvs] = handler->sockServer->Accept();
if(handler->sockConvs[handler->nconvs]->IsConnected() && handler->nconvs < 10)
{
handler->frames[handler->nconvs] = new MyFrame(NULL);
handler->frames[handler->nconvs++]->Show();
}
}
The class MyFrame handler of Thread:
Code:
class MyFrame : public wxFrame
{
friend class listenThread;
public:
/* other stuff ... */
private:
/* other stuff ... */
private:
listenThread *myThread;
// Both initialized in MyFrame class constructor
wxSocketServer *sockServer;
wxIPV4address addr;
wxSocketBase *sockConvs[10];
MyFrame *frames[10];
int nconvs;
};
Now the problem is that when a client connects to my Application, the listening thread receives this Incoming connection(for each connection, obiviusly, it uses a different SocketBase from sockConvs array) and allocates (as you can see) a new MyFrame.
BUT! at the end of Entry method my new Frame make closed.
Why?
Thank you!