

Thanks for your help
The problem is that this is very implementation-depedant and really is mostly thread-related stuff and nothing to do with sockets.GianT wrote:HiI want my application to perform both client and server actions. I've done a timer and associated a function in which I will put the code of the client part, and I guess that I have to make a thread to put the code of the server part. I would just like to have a complete example of sending and receiving datas with wxSocketServer and wxSocketClient. I found examples on sockets on the internet, but none about wxSockets
.
Thanks for your help
Maybe this helpsRyan Norton wrote:The problem is that this is very implementation-depedant and really is mostly thread-related stuff and nothing to do with sockets.GianT wrote:HiI want my application to perform both client and server actions. I've done a timer and associated a function in which I will put the code of the client part, and I guess that I have to make a thread to put the code of the server part. I would just like to have a complete example of sending and receiving datas with wxSocketServer and wxSocketClient. I found examples on sockets on the internet, but none about wxSockets
.
Thanks for your help
Generally note that none of the wx classes are really thread safe, so be careful...
Not sure if I got the correct context (just having my first coffee todayKaReL wrote: what if you create a thread, with a wxEvtHandler object inside... Will it be able to receive events?
Code: Select all
class MyServer_Thread : public wxEvtHandler, public wxThread
Code: Select all
BEGIN_EVENT_TABLE(MyServer_Thread, wxEvtHandler)
EVT_SOCKET(SERVER_EVENT, MyServer_Thread::OnServerEvent)
END_EVENT_TABLE()
Code: Select all
EVT_SOCKET(SOCKET_ID, newProgramFrame::OnSocketEvent)
Code: Select all
addr.LocalHost();
addr.Service(3050);
m_server = new wxSocketServer(addr, wxSOCKET_WAITALL);
m_server->SetEventHandler(*this, SOCKET_ID);
m_server->SetNotify(wxSOCKET_CONNECTION_FLAG |
wxSOCKET_INPUT_FLAG |
wxSOCKET_LOST_FLAG);
m_server->Notify(true);
if (! m_server->Ok())
{
wxMessageBox("Could not listen at the specified port !", _T("About Minimal"),
wxOK | wxICON_INFORMATION, this);
return;
}
else
{
wxMessageBox(wxString::Format("Server listening on port [%u]\n\n",
(unsigned int)(addr.Service())),"Listening...");
}
Code: Select all
void newProgramFrame::OnSocketEvent(wxSocketEvent& event)
{
switch(event.GetSocketEvent())
{
case wxSOCKET_INPUT : wxMessageBox("wxSOCKET_INPUT\n"); break;
case wxSOCKET_LOST : wxMessageBox("wxSOCKET_LOST\n"); break;
case wxSOCKET_CONNECTION : wxMessageBox("wxSOCKET_CONNECTION\n"); break;
default : wxMessageBox("Unexpected event !\n"); break;
}
}
Code: Select all
switch(event.GetSocketEvent())
{
case wxSOCKET_INPUT : wxMessageBox("wxSOCKET_INPUT\n"); break;
case wxSOCKET_LOST : wxMessageBox("wxSOCKET_LOST\n"); break;
case wxSOCKET_CONNECTION : wxMessageBox("wxSOCKET_CONNECTION\n");m_server->Accept();break;
default : wxMessageBox("Unexpected event !\n"); break;
}
Code: Select all
case wxSOCKET_CONNECTION : m_server->Accept();Sleep(3000);wxMessageBox("wxSOCKET_CONNECTION\n");break;