Problem with socket input events

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
BinaryShinigami
In need of some credit
In need of some credit
Posts: 4
Joined: Thu Sep 04, 2008 1:51 am

Problem with socket input events

Post by BinaryShinigami » Wed Apr 01, 2009 7:58 pm

Hey guys. I'm creating a fairly simple IRC client to play with sockets and I'm having some problems with reading from the socket.

I know how to read and all that the problem is that it seems that the events stop being generated after the first 3 events. I have Left a pretty bare wxSOCKET_INPUT clause in my select case where is just peeks 1 byte so it should keep getting the same byte over and over to test what was going on and it only gets the 1 byte 3 times then it stops trying. I have put wxMessageBoxes at the beginning and end of the input case to see how it is executed and it seems that the event is generated and then again before the 1st pass through the function has been ended.

Example:

Code: Select all

case wxSOCKET_INPUT:
{
    wxMessageBox(wxT("Input Generated"),wxT("INFO"));
    Sock->Peek(buffer,1);
    wxMessageBox(wxT("Ended."),wxT("INFO"));
}
The output is basically message boxes in this order:
Input Generated
Input Generated
Input Generated
Ended
Ended
Ended

Then it stops altogether can and from what I understand since I only peek'd the bytes it should keep generating the event because I have never taken it off the socket buffer.

Can someone help me with this all I want is it to keep reading and not just stop like that I have tried all of the flags for the socket like BLOCK, NOWAIT, WAITALL etc... and nothing seemed to make any difference.

protocol
Moderator
Moderator
Posts: 680
Joined: Wed Jan 18, 2006 6:13 pm
Location: Dallas, TX
Contact:

Post by protocol » Wed Apr 01, 2009 10:35 pm

You can't expect the same/desired behavior with just any combination of flags.

Use wxSocketBase::SetFlags(wxSOCKET_WAITALL)

Also its best practice to use ::wxLogDebug(...) rather than wxMessageBox(...)

Regards.
/* UIKit && wxWidgets 2.8 && Cocoa && .Net */
QuRegExmm
wxPCRE & ObjPCRE - Regex It!

Post Reply