Subject Re: Error in websocket
From Robert Diaz <> <Robert Diaz <>>
Date Mon, 17 Jun 2019 06:28:25 +0100
Newsgroups xb2net

Javascript Code
****************
function valid_func_agets(o, event) {
        var ws;
        wsURL = (isSecure ? 'wss://' : "ws://") + window.location.host + '/valid_func_agets';
        if (ws && ws.url == wsURL)
            wsURL = wsURL.toLowerCase();
        wss = localStorage.getItem('ws');
        if (wss!=undefined && wss.readyState == 1 && wss.url == wsurl) {
          
        }
        else {
            if (isSecure)
                wsURL = wsURL.replace("ws:", "wss:");
            if ('WebSocket' in window) {
                ws = new WebSocket(wsURL);
            } else if ('MozWebSocket' in window) {
                ws = new MozWebSocket(wsURL.value);
            } else {
                logError('This browser does not support WebSocket!');
                return;
            }
           // localStorage.setItem('ws', JSON.stringify(ws));
        }
        var arr = getagets();
        var agets = arr[0];
        var browse = gettabledata($('#' + tblid));
        ws.onopen = function () {
            ws.send(cur_tabindex)
            ws.send(JSON.stringify(agets));
        }
        var count = 0;
        ws.onmessage = function (event) {
            var a = event.data;
            if (event.data.split('@')[0] == 'agetshtml') {
                mydata = event.data.split('@')[1];
                $('[name=agets]').html(mydata);
            }
            else if (event.data.split('@')[0] == 'tdyesno') {
                mydata = event.data.split('@')[1];
                if (event.data != null) {
                    if (confirm(mydata)) {
                        reply = 'Yes';
                        ws.send(reply);
                    }
                    else {
                        reply = 'No';
                        ws.send(reply);
                    }
                }

            }
            else if (event.data.split('@')[0] == 'helphtml') {
                $("#agetshelp").html(event.data.split('@')[1]);
                $("#agetnum").val(cur_tabindex);
                modalhelp('modalpopup_helpagets')//$('.modalpopup_helpagets').show();

                popupclickrow($('.modalpopup_helpagets').find("#myTable tbody tr:first"));

            }

        }
        ws.onclose = function () {
            popupclickrow($('.modalpopup_helpagets').find("#myTable tbody tr:first"));
        }


        return false;
    }
}



Xb2.net Function//backend
****************************************
procedure ws_valid_func_agets(osock)
****************************************
local str,odlg1,agetnum,oclient:=threadobject(),cError,crecv,adata:={},obrow,agets7,odlg:=oodlg,item,agets:={},vodlg:=vvodlg,o,array,i,markup
local count:=1,omle
oclient:cargo:=array(5)
oclient:cargo[1]:=oSock
oclient:cargo[2]:=odlg
odlg:helphtml:=''
odlg:msghtml:=''
ODLG:browone := 0
while .t.
      cRecv := oSock:recv()
      if !oSock:Connected
         exit
      elseif cRecv == NIL .or. oSock:OpCode == NIL
         if !oSock:Ping("", 3000, @cError)
            ? cError
            exit
         endif
      elseif upper(cRecv) == "QUIT"
         oSock:send("Good bye...")
         oSock:close()
         exit
      else
        if count==1
            agetnum:=val(cRecv)
        elseif count==2
           agets := cRecv
        elseif count==3
           agets7 := cRecv
         //  exit
        elseif count==3
           omle := cRecv
           if omle<>'[]'
               omle:=json2var(omle)
               for i:=1 to len(omle)
                  odlg:ogp1:omle1:setdata(omle[i])
               next

           endif
           exit
        endif
      endif
      count++
end
str:=agets+'@'+agets7
agets:=odlg:cargo[1]
iif(len(odlg:cargo)>8,aGets7:=oDlg:cargo[9],)
getcontrols2(@str,@agets,@agets7,odlg)
o:=agets[agetnum]
oDlg:cargo[1]:=aGets
iif(len(odlg:cargo)>8,oDlg:cargo[9] :=aGets7,)
oclient:cargo[2]:=odlg
if !empty(o:bvalid)  .and. valtype(o:bvalid)='B'
     if eval(o:bvalid,o)
         eval(odlg:keyboard,xbeK_ENTER,o)
     endif
else
   eval(odlg:keyboard,xbeK_ENTER,o)
endif
odlg:chtml:=eval(odlg:agetshtml,odlg)
osock:send('agetshtml@'+odlg:chtml)
if odlg:msghtml!='' .and. (odlg:helphtml==nil   .or. odlg:helphtml=='' )
   osock:send('msghtml@'+odlg:msghtml)
endif
if odlg:helphtml!=nil   .and. odlg:helphtml!=''
osock:send('helphtml@'+odlg:helphtml)
endif
for i:=1 to len(odlg:obrow:adata)
      if !empty(odlg:obrow:adata)  .and. valtype(odlg:obrow:adata)='A'  .and. len(odlg:obrow:adata)>0
                  markup:='<tr onclick="clickrow(this);">'
                  markup+=eval(odlg:obrow:AddRow,threadobject(),i)
                  markup+='</tr>'
                  osock:send('browsehtml@'+markup)
       endif
next
eval(odlg:agets7html,odlg)
oSock:destroy()
xbSSLFreeErrorQueue()
return

ISSUE :

valid_func_agets() is calling on onkeydown event of each input in the forms, each time websocket is opening and closing. websocket is used to get client response when executing backend function.
When executing o:valid, meanwhile confirmbox is there, based on client response we need to execute remaining part of o:bvalid codeblock.

When alt+down pressing in each input ,another function alt_down_agets() function is calling[ws_alt_down_agets() backend function], where other websocket with different url is creating to load help file. after fully loaded,that socket wil close. In each input websocket will open and close.

Above code is working fine when single user works in the form. When multi user access the form and click alt-down help or iterating throught the form, websocket get crashed and program get hang.










Recent messages in this thread
 
-# Error in websocket Robert Diaz <> 28-May-2019 03:30 am
.-# Re: Error in websocket Boris Borzic <bb> 28-May-2019 10:03 am
..-# Re: Error in websocket Robert Diaz <> 29-May-2019 01:40 am
...-# Re: Error in websocket Boris Borzic <bb> 29-May-2019 09:53 am
....-# Re: Error in websocket (Current message) Robert Diaz <> 17-Jun-2019 01:28 am
.....-# Re: Error in websocket Boris Borzic <bb> 17-Jun-2019 09:43 am
......-# Re: Error in websocket Robert Diaz <> 19-Jun-2019 12:50 am
.......-# Re: Error in websocket Robert Diaz <> 19-Jun-2019 07:18 am
........\# Re: Error in websocket Boris Borzic <bb> 19-Jun-2019 08:55 am