Page 1 of 1

Socket events not processed when user moves or resizes window

Posted: Fri May 11, 2018 7:25 pm
by kurtNovoselic
I have this problem working with socket events, I'm receiving data from TCP client handling reception with events.
It works fine, I process data from client and then show a message in wxTextCtrl (multiline) with information for user.
But when I move window or select text in wxTextCtrl my app doesn't send any kind of data to client.
I'm not working with secondary threads for this at the moment.

Code: Select all

BEGIN_EVENT_TABLE(ServerDialog,wxDialog)
    //(*EventTable(ServerDialog)
    //*)
    EVT_BUTTON(ID_BTNHIDE,  ServerDialog::ClickHide)
    EVT_BUTTON(ID_BTNEXIT,  ServerDialog::OnQuit)
    EVT_CLOSE(ServerDialog::OnCloseWindow)
    EVT_BUTTON(ID_BTNSTART, ServerDialog::OnServerStart)
    EVT_SOCKET(SERVER_ID,  ServerDialog::OnServerEvent)
    EVT_SOCKET(SOCKET_ID_WEB, ServerDialog::OnSocketEventWeb)
    EVT_SOCKET(SOCKET_ID_REG, ServerDialog::OnSocketEventReg)
END_EVENT_TABLE()
Function working with event EVT_SOCKET(SOCKET_ID_REG, ServerDialog::OnSocketEventReg):

Code: Select all

void ServerDialog::OnSocketEventReg(wxSocketEvent& event)
{
    // The socket that had the event
    wxSocketBase* sock = event.GetSocket();

    switch(event.GetSocketEvent())
    {
        case wxSOCKET_CONNECTION:
            break;

        case wxSOCKET_INPUT:
        {
            /****************************************************************************************************************************/
            char buf[10] = {0,0,0,0,0,0,0,0,0,0};
            wxDateTime dt = wxDateTime().Now();
            //Formatear texto de hora y fecha para enviar al servidor...
            wxString strdt = dt.Format("%H:%M:%S %d/%m/%y");
            sock->Read(buf, sizeof(buf)-1);   // Se reciben máximo 9 caracteres (se deja espacio para \0)

            char c1er_ = buf[0];
            // "(tipo)(space)(d1d2d3d4)" 6 caracteres + 1 nulo => máximo = 7
            // Verificar integridad de formato de peso...
            if((c1er_ == 'A' || c1er_ == 'B' || c1er_ == 'C' || c1er_ == 'D')  && buf[1]== ' ' && sock->LastCount() <= 7)
            {
                wxString str_peso = &buf[2];
                if(str_peso.IsNumber())
                {
                    // Registro normal...
                    txtMsg->AppendText(buf);        // Mostrar cadena de registro
                    txtMsg->AppendText(" ");
                    txtMsg->AppendText(strdt);
                    txtMsg->AppendText("\n");
                    // Acá se envia la información de tiempo para registro en arduino
                    sock->Write(strdt.c_str(), 18);

                    // Modo TEST
                    if(bmodoTest)
                       txtMsg->AppendText("(MODO PRUEBA)\n");
                    else
                    {   // Finalmente se registra...
                        RegData(buf, strdt);
                    }

                }
            }
            else
            {
                int ncar = sock->LastCount();
                // Si es solo 1 byte y es 'N' => Fin de molinada actual...
                if(c1er_ == 'N' && ncar == 1)
                {
                    // Respuesta... (no necesaria)
                    txtMsg->AppendText("Fin de molinada actual\n");
                    // Leer agua (para conocer valor inicial antes del consumo de agua).
                    if(bmodoTest)
                    {
                        wxString str;
                        str.Printf("%.1f",cntAguam3);
                        txtMsg->AppendText("Contador acumulado (m3): " + str + "\n");
                        txtMsg->AppendText("(MODO PRUEBA)\n");
                    }
                    else
                    {
                        cntAguam3 = this->LeerAgua();   // devuelve valor de agua en m3...
                    }

                    // Este valor se usará para registrar y ya no la lectura actual en cada pesaje.
                }
                else
                    // Si el primer caracter y único byte es 'F' => Obtener formulación...
                    if(c1er_ == 'F' && ncar == 1)
                    {
                        wxString strFormula = strCmdFormula;

                        if(bmodoTest == true)
                        {
                            strFormula = "S0000 0000 0000 0000 ";
                        }
                        txtMsg->AppendText("F: " + strFormula + "\n");
                        sock->Write(strFormula.c_str(), strFormula.length()+1);
                    }
                    else
                        // Si solo es H enviar respuesta de Fecha y hora
                        if(c1er_ == 'H' && ncar == 1)
                        {
                            // Acá se envia la información...
                            sock->Write(strdt.c_str(), 18);
                            //txtMsg->AppendText("FyH " + strdt.c_str() + "\n");
                        }
                        else
                            // Si solo es H enviar respuesta de Fecha y hora
                            if(c1er_ == 'K' && ncar == 1)
                            {
                                // Acá se envia la información...
                                sock->Write("x", 1);
                                txtMsg->AppendText("ACK\n");
                            }
                            else
                            {
                                txtMsg->AppendText("Reset\n");
                                sock->Discard();
                            }
            }
            /*****************/
            break;
        }

        case wxSOCKET_LOST:
        {
            wxIPV4address remote;
            sock->GetPeer(remote);
            txtMsg->AppendText(" Se ha cerrado la conexión con el registrador...\n");
            txtMsg->AppendText("IP Cliente: " + remote.IPAddress()+"\n");
            unsigned short nport = remote.Service();
            txtMsg->AppendText("Puerto: " + wxString().Format("%d", nport) +"\n");
            nclients--;
            if(nclients <0)
                nclients = 0;
            txtMsg->AppendText("N° Clientes: " + wxString::Format("%i",nclients) +"\n");
            st_estado->SetLabel("No Conectado");
            Led1->SwitchOff();   // Apagar led de conexión aceptada

            sock->Close();
            //sock->Destroy();
            break;
        }

        case wxSOCKET_OUTPUT:
            break;
    }
}
I was searching in forum and something like this viewtopic.php?t=42379 sounds similar.

Re: Socket events not processed when user moves or resizes window

Posted: Fri May 11, 2018 7:30 pm
by doublemax
Platform. wxWidgets version?

If you're using wx 3.0.3 or older, please try with the latest version from GIT.

Re: Socket events not processed when user moves or resizes window

Posted: Fri May 11, 2018 9:53 pm
by kurtNovoselic
doublemax wrote:Platform. wxWidgets version?

If you're using wx 3.0.3 or older, please try with the latest version from GIT.
3.1.0

Re: Socket events not processed when user moves or resizes window

Posted: Fri May 11, 2018 9:55 pm
by kurtNovoselic
I am using 3.1.0 wxWidget with codeblocks and TDM-GCC-64 in W7

Re: Socket events not processed when user moves or resizes window

Posted: Mon May 14, 2018 2:16 pm
by ONEEYEMAN
Hi,
Do you handle any mouse events?
Can you reproduce the behaviour in the socket samples (client/server)?

Thank you.

Re: Socket events not processed when user moves or resizes window

Posted: Mon May 14, 2018 3:00 pm
by kurtNovoselic
ONEEYEMAN wrote:Hi,
Do you handle any mouse events?
Can you reproduce the behaviour in the socket samples (client/server)?

Thank you.
No.. I am not handling any mouse events....
I'll try with the socket samples...

Re: Socket events not processed when user moves or resizes window

Posted: Tue May 15, 2018 9:31 pm
by kurtNovoselic
Good News!:.. for me :D
I did not try with samples.. But I try using the 3.0.4 ver of wxWidgets and... it works.
Thanks!...

Re: Socket events not processed when user moves or resizes window

Posted: Wed May 16, 2018 2:10 pm
by ONEEYEMAN
Hi,
This is actually means it is a regression in wx 3.1.
For testing purposes - can you try to build Git HEAD (latest master) and see if its reproducible there?

Also, I strongly advise you to check the samples on 3.1 and see if you can reproduce it there. Because if you can it means it is an actual regression and it has to be fixed.

So if you still have 3.1 sources available - please try with the sample. If it produces the same behaviour - please file a bug on trac.wxwidgets.org. Say wx version, OS version, compiler version and steps to reproduce the issue.

Hopefully Vadim will try to see what is happening.

Thank you.