wxSocketServer Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ANtlord
In need of some credit
In need of some credit
Posts: 8
Joined: Fri Jun 29, 2012 4:41 pm

wxSocketServer

Post by ANtlord »

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:

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);
Socket1 is object of class "wxSocketServer", SERVER_ID = 666, SOCKET_ID = 100.

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");
}
Event, when client send command

Code: Select all

void StilusServerFrame::OnSocket(wxSocketEvent &e){
    *Text1<<wxT("New command\n");
}
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSocketServer

Post by doublemax »

Did you check the "ipc" sample which does exactly what you're trying to do?
Use the source, Luke!
ANtlord
In need of some credit
In need of some credit
Posts: 8
Joined: Fri Jun 29, 2012 4:41 pm

Re: wxSocketServer

Post by ANtlord »

No, I didn't. I looking now this samle, and I don't see events for connection. wxSocket has wxEVT_SOCKET, and I can't detect event for wxServer and wxClient.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxSocketServer

Post by doublemax »

Sorry, i actually meant the "sockets" sample. But I've never worked with sockets myself, so i can't help any further. Maybe someone else can step in.
Use the source, Luke!
ANtlord
In need of some credit
In need of some credit
Posts: 8
Joined: Fri Jun 29, 2012 4:41 pm

Re: wxSocketServer

Post by ANtlord »

So, this problem has next solution. In method of socket's event for new command I add next code

Code: Select all

wxSocketBase *sock = e.GetSocket();
unsigned char c;
sock->Read(&c, 1);
*Text1<<wxT("new command\n");
SOLVED!
Post Reply