wxSocketServer
Posted: Tue Jul 17, 2012 6:00 pm
Good day, wxDevelopers.
I began study networks, and decided to develop application on likest wxWidgets.
I read Julian Smart and research wxSocket's sample. But I got issue. My "server" set connection with client and it receive one command from client. My "server" don't get second, third, fourthy commands, etc. Maybe it receive, but it don't respond.
I use wxWidgets 2.9.3, Arch linux (kernel 3.4), CodeBlocks 10.05, gcc 4.7
Code in myframe's constructor:
Socket1 is object of class "wxSocketServer", SERVER_ID = 666, SOCKET_ID = 100.
Event, when client tries to connect
Event, when client send command
I began study networks, and decided to develop application on likest wxWidgets.
I read Julian Smart and research wxSocket's sample. But I got issue. My "server" set connection with client and it receive one command from client. My "server" don't get second, third, fourthy commands, etc. Maybe it receive, but it don't respond.
I use wxWidgets 2.9.3, Arch linux (kernel 3.4), CodeBlocks 10.05, gcc 4.7
Code in myframe's constructor:
Code: Select all
wxIPV4address addr;
addr.Hostname(_("localhost"));
addr.Service(6667);
Socket1 = new wxSocketServer(addr);
Socket1->SetEventHandler(*this, SERVER_ID);
Socket1->SetNotify(wxSOCKET_CONNECTION_FLAG);
Socket1->Notify(true);
Connect(SERVER_ID,wxEVT_SOCKET,(wxObjectEventFunction)&StilusServerFrame::OnServer);
Connect(SOCKET_ID,wxEVT_SOCKET,(wxObjectEventFunction)&StilusServerFrame::OnSocket);
Event, when client tries to connect
Code: Select all
void StilusServerFrame::OnServer(wxSocketEvent &e){
wxSocketServer* pServerSocket = (wxSocketServer*) e.GetSocket();
wxSocketBase *CurSocket1 = pServerSocket->Accept(false);
CurSocket1->SetEventHandler(*this, SOCKET_ID);
CurSocket1->SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG| wxSOCKET_OUTPUT_FLAG);
CurSocket1->Notify(true);
*Text1<<wxT("New connect\n");
}
Code: Select all
void StilusServerFrame::OnSocket(wxSocketEvent &e){
*Text1<<wxT("New command\n");
}