the z locale is apparently necessary for the websockets handlers (which is how 
J communicates with websockets).

The documentation is here: http://www.jsoftware.com/jwiki/Guides/JqtWebsocket, 
and there are also demos with j8.

If the handlers have to be in z, I might as well put the tracking list for 
sockets and connections there, as the handlers need to access the tracking 
lists in order to dispatch to the right code, and there can only be one handler 
in program.


I rely on some favorite utility verbs, that I keep in z.  Nothing else is in z 
though.

" you can call it yourself if you wish to do so (and you couldmaintain your own 
queue of commands to feed it, if you want that"

I'm surprised to hear this.  I assume J/QT would also "double call" it, if I 
did.  Would probably cause its own problems.  Its possible that you are 
describing a technique I don't know of, in maintaining my "own queue of 
commands"




----- Original Message -----
From: Raul Miller <rauldmil...@gmail.com>
To: Programming forum <programm...@jsoftware.com>
Cc: 
Sent: Wednesday, February 12, 2014 7:52:43 PM
Subject: Re: [Jprogramming] Qt websockets and doevents

I am a little uncomfortable, reading ad-hoc code in the 'z' locale. Why not
use some other locale?

Also, I am not clear what you are asking for, with the event handler, but
clearly you can call it yourself if you wish to do so (and you could
maintain your own queue of commands to feed it, if you want that).

Thanks,

-- 
Raul



On Wed, Feb 12, 2014 at 7:23 PM, Pascal Jasmin <godspiral2...@yahoo.ca>wrote:

> A minor wierdness with websockets is that connect returns a string socket,
> whereas the event handlers have integer sockets.
>
> I was hoping that 6!:2 allowed for event handlers to process messages, but
> it doesn't appear to.  Does such a command exist?  A bit like the old vb
> windows 3.1 doevents()/yield()
>
> Anyways, if you load the included code listing, and run
>
> testws a:
>
> you will note that it fails to unload/close client sockets (line wd 'ws
> query 1' returns open clients)
>
> if you run the lines inside testws individually in repl, it works. (closes
> everything)
>
>
>
> cocurrent 'z'
> wssockets =: i.0 NB.
> wsconnections =: i.0
>
> deleteitem_z_ =:  {. , >:@[ }. ]
> defaults1 =: ([`]@.(0=#@>@[))
> defaults =: defaults1"0 0 f.
> fixlenx =: 1 : (':';'((#y) {. x) u y')
> iorinf =: iorinf =: (#@[ _:^:= i.)
> inl_z_ =: (cocurrent@] ".@] [)"1 0
> pD_z_ =:  1!:2&2
>
> wscln_handler_z_=: 3 : 0
> 'evt sk'=. y
> if. evt = jws_onMessage do.
> smoutput 'client: ' wss0_jrx_
> elseif. evt = jws_onOpen do.
> smoutput 'connected ', ": sk
> 'onOpen 1' inl wsconnections {~ wssockets i. sk
> elseif. evt = jws_onClose do.
> smoutput 'disconnected ' , ": sk
> 'onClose 1' inl wsconnections {~ wssockets i. sk
> elseif. evt = jws_onError do.
> smoutput wsc0_jrx_
> end.
> EMPTY
> )
>
> wssvr_handler_z_=: 3 : 0
> 'evt sk'=. y
> if. evt = jws_onMessage do.
> smoutput 'server: ' wss0_jrx_
> NB.  assert. _1 ~: r
> elseif. evt = jws_onOpen do.
> smoutput 'Serv connected ', ": sk
> NB. pD datatype sk
> 'onOpen 1' inl ((sk);'server') conew 'wsconnection'
> NB. 'onOpen 1' inl wsconnections {~ wssockets i. sk
> elseif. evt = jws_onClose do.
> smoutput 'Serv disconnected ' , ": sk
> 'onClose 1' inl wsconnections {~ wssockets i. sk
> elseif. evt = jws_onError do.
> smoutput 'error ', wss0_jrx_
> end.
> EMPTY
> )
>
> addsockconn =: 4 : 0
> pD 'adds'
> pD wssockets_z_ =: wssockets_z_ , x
> pD wsconnections_z_ =: wsconnections_z_ , y
> )
> delsock=: 3 : 0
> if. _ > i =. y iorinf~ wssockets do.
> wssockets =: i deleteitem wssockets
> wsconnections =: i deleteitem wsconnections
> end.
> )
> delconn=: 3 : 0
> if. _ > i =. y iorinf~ wsconnections_z_ do.
> wssockets_z_ =: i deleteitem wssockets_z_
> wsconnections_z_ =: i deleteitem wsconnections_z_
> end.
>
> )
> coclass 'wsconnection'
> connected =: 0
> create =: 3 : 0
> 'socket conntype commands auth' =: y defaults fixlenx
> a:;'client';'testcommands';'authserver'
> pD 18!:5 ''
> socket (addsockconn ]]) 18!:5 ''
> )
> createServer =: 3 : 0
>
> )
> onOpen =: 3 : 'connected =: 1'
> onClose =: 3 : 0
> connected =: 0
> delconn 18!:5 ''
> )
> close =: 3 : 'wd ''ws close '', ": socket'
>
> NB. ( [conntype = 'client'];[commandslocale];[authlocale])
> new_wsconnection_ 'localhost 3000' ('addr port') > wsconnectionObj
> new =: 4 : 0 NB. called for client connection
> s =. 0 ". wd 'ws connect ws://', y
> (s ; x) conew >18!:5 ''
> )
>
> NB. =========================================================
> wd 'ws listen 3000'
> cocurrent 'base'
> testws =: 3 : 0
> a: new_wsconnection_ 'localhost 3000'
> a: new_wsconnection_ 'localhost 3000'
> 6!:3 (2)
> 'close 1' inl  '''client'' -: conntype' (] #~ inl) wsconnections_z_ NB.
> closes all clients (cascades cleanup)
> 6!:3 (1)
> pD  'q0';wd 'ws query 0'
> pD  'q1';wd 'ws query 1'
> )
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to