Reputation: 1
I'm developing an application which needs to have a permanent server socket listening, so I put it in a thread, here there is the class I've written for it:
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:
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 the Entry method my new Frame is closed. Why?
Thank you!
Upvotes: 0
Views: 1932