Hi!
I have big trouble with sockets, they does simply not work as expected(documentation). There are two threads, thread one is the server In the entry-methode:
wxIPV4address addr;
if(!addr.Service(1180)) {
textArea->AppendText("No service...");
}
wxSocketServer ss(addr);
if(!ss.Ok()) {
textArea->AppendText("Socket not ok...");
return;
}
wxSocketBase * con = ss.Accept(true); if (con->IsConnected() && con->WaitForRead(10)) {
wxChar buffer[128] ;
con->Read(buffer, 127);
textArea->AppendText(buffer);
} else {
textArea->AppendText("Error or timeout...");
}
That was the server and here comes the client: In entry-methode 2:
wxIPV4address addr;
if(!addr.Hostname("localhost")) {
textArea->AppendText("No service...");
}
if(!addr.Service(1180)) {
textArea->AppendText("No host...");
}
wxSocketClient *m_sock = new wxSocketClient(wxSOCKET_BLOCK | wxSOCKET_WAITALL);
m_sock->Connect(addr, true);
if (m_sock->IsConnected()) {
textArea->AppendText("Writing...");
m_sock->Write("HI", 2);
} else {
textArea->AppendText("Not connected...");
}
OK, that work as expected, but, when the serversocket has accepted, and the retuned wxSocketBase* con tries to read (there has to be readable data, because accepted returned!), then there is nothing to read?! It just times out. What is wrong here? Is there a bug again, that these methode are not working? Or doesn't work threads and sockets together? Or do i have to use events(following the documentation, this doesn't seem to be neccessary)?
thanks |