wxSocketBase: Exiting after reading data Topic is solved
Re: wxSocketBase: Exiting after reading data
In that case the only thing I can propose - provide SSCCE for reproducing behaviour.
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxSocketBase: Exiting after reading data
I don't do anything peculiar than information I have provided. All I do is:
1. create wxSocketClient passing no argume.
2. Set Notify flags
3. Write to Socket
4. In response to Socket read event I just call the method we have been discussing.
Nothing peculiar as you can see!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: wxSocketBase: Exiting after reading data
If you are responding to a wxSOCKET_INPUT event, then you can simply use Read(buffer, len) to read all available bytes and return. I am pretty sure that Read is guaranteed to get something if a wxSOCKET_INPUT event has occurred.
The following works for me in both Windows and Linux.
Code: Select all
void MainFrame::OnSocketEvent(wxSocketEvent& event)
{
wxLogMessage("OnSocketEvent: ");
wxSocketBase* sockBase = event.GetSocket();
// Process the event.
switch (event.GetSocketEvent())
{
case wxSOCKET_INPUT:
{
wxLogMessage("wxSOCKET_INPUT\n");
char buf[256];
// Read the message
wxUint32 lenRd = sockBase->Read(buf, 256).LastCount();
if (!lenRd)
{
wxLogMessage("Failed to read any data.\n");
return;
}
else
{
wxLogMessage("Read %d bytes.\n", lenRd);
}
wxLogMessage("Rx: %s \n", wxString::FromUTF8(buf, lenRd));
break;
}
...
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxSocketBase: Exiting after reading data
That sounds great except I don't know buffer size. May be I have to make it the biggest possible. I will try that option too!iwbnwif wrote: ↑Fri Jun 07, 2019 1:03 pmIf you are responding to a wxSOCKET_INPUT event, then you can simply use Read(buffer, len) to read all available bytes and return. I am pretty sure that Read is guaranteed to get something if a wxSOCKET_INPUT event has occurred.
The following works for me in both Windows and Linux.
Code: Select all
void MainFrame::OnSocketEvent(wxSocketEvent& event) { wxLogMessage("OnSocketEvent: "); wxSocketBase* sockBase = event.GetSocket(); // Process the event. switch (event.GetSocketEvent()) { case wxSOCKET_INPUT: { wxLogMessage("wxSOCKET_INPUT\n"); char buf[256]; // Read the message wxUint32 lenRd = sockBase->Read(buf, 256).LastCount(); if (!lenRd) { wxLogMessage("Failed to read any data.\n"); return; } else { wxLogMessage("Read %d bytes.\n", lenRd); } wxLogMessage("Rx: %s \n", wxString::FromUTF8(buf, lenRd)); break; } ...
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: wxSocketBase: Exiting after reading data
This solves my issue.iwbnwif wrote: ↑Fri Jun 07, 2019 1:03 pmIf you are responding to a wxSOCKET_INPUT event, then you can simply use Read(buffer, len) to read all available bytes and return. I am pretty sure that Read is guaranteed to get something if a wxSOCKET_INPUT event has occurred.
The following works for me in both Windows and Linux.
Code: Select all
void MainFrame::OnSocketEvent(wxSocketEvent& event) { wxLogMessage("OnSocketEvent: "); wxSocketBase* sockBase = event.GetSocket(); // Process the event. switch (event.GetSocketEvent()) { case wxSOCKET_INPUT: { wxLogMessage("wxSOCKET_INPUT\n"); char buf[256]; // Read the message wxUint32 lenRd = sockBase->Read(buf, 256).LastCount(); if (!lenRd) { wxLogMessage("Failed to read any data.\n"); return; } else { wxLogMessage("Read %d bytes.\n", lenRd); } wxLogMessage("Rx: %s \n", wxString::FromUTF8(buf, lenRd)); break; } ...
Thanks everyone who helped!
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?