I'm still not sure what are the purpose of the 6!:3 used.
websocket itself is asynchronus.  You need not poll the event
loop becuae tne events will call you instead.  Once you started
connection inside testws, you should exit testws wihtout waiting
for result.

If you want the exact sequence then the use smoutput can be
problematic because it relies on jqt frontend.  Try use 
stdout or stderr or log to a file instead. Not sure if
this is relevant to your case.

Ср, 12 фев 2014, Pascal Jasmin писал(а):
> The code with no nouns in z.  The server and client handlers do nothing with 
> messages other than print to console, and so there should be no concern about 
> running it.  The code is there to exercise opening and closing sockets.
> 
> There is both a client and server loop handler, but as mentioned, nothing is 
> done onMessage in each.
> 
> There are only 2 lines of code that are run:
> 
>    a: new_wsconnection_ 'localhost 3000'
> 
> 
> creates a new client, that will also create a new server.  1 socket and 
> locale numbers are placed in array for each.
> 
>    'close 1' inl  '''client'' -: conntype' (] #~ inl) wsconnections_ws_
> 
> 
> That line has been commented out, but it does: For connections of conntype 
> 'client' that are in the connectionslist, close them. 
> 
> 
> I've narrowed down the issue to 6!:3 does not allow the server handler to 
> process messages.
> 6!:3 also happens to not be necessary to get client handler to process.  
> These happen in order after connect.
> You can confirm this by noticing the order of "Serv connect" prints in 
> console.  These occur after the query 1 and query 0 regardless of the length 
> of delay in 6!:3 line.
> The server messages process after code stops.
> 
> 
> cocurrent 'ws'
> wssockets =: i.0 NB.
> wsconnections =: i.0
> 
> wscln_handler_z_ =: wscln_handler =: 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_ws_ {~ wssockets_ws_ i. sk
> elseif. evt = jws_onClose do.
>   smoutput 'disconnected ' , ": sk
>  'onClose 1' inl wsconnections_ws_ {~ wssockets_ws_ i. sk
> elseif. evt = jws_onError do.
>   smoutput wsc0_jrx_
> end.
> EMPTY
> )
> 
> wssvr_handler_z_ =: wssvr_handler =: 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_ws_ {~ wssockets_ws_ i. sk
> elseif. evt = jws_onError do.
>   smoutput 'error ', wss0_jrx_
> end.
> EMPTY
> )
> 
> addsockconn =: 4 : 0
> pD 'adds'
> pD wssockets_ws_ =: wssockets_ws_ , x
> pD wsconnections_ws_ =: wsconnections_ws_ , y
> )
> delsock=: 3 : 0
> if. _ > i =. y iorinf~ wssockets do.
> wssockets_ws_ =: i deleteitem wssockets_ws_
> wsconnections_ws_ =: i deleteitem wsconnections_ws_
> end.
> )
> delconn=: 3 : 0
> if. _ > i =. y iorinf~ wsconnections_ws_ do.
> wssockets_ws_ =: i deleteitem wssockets_ws_
> wsconnections_ws_ =: i deleteitem wsconnections_ws_
> end.
> 
> )
> coclass 'wsconnection'
> connected =: 0
> create =: 3 : 0
> 'socket conntype commands auth' =: y defaults fixlenx 
> a:;'client';'testcommands';'authserver'
> pD 18!:5 ''
> socket (addsockconn_ws_ ]]) 18!:5 ''
> )
> createServer =: 3 : 0
> 
> )
> onOpen =: 3 : 'connected =: 1'
> onClose =: 3 : 0
> connected =: 0
> delconn_ws_ 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 (0.2)
> NB. 'close 1' inl  '''client'' -: conntype' (] #~ inl) wsconnections_ws_ NB. 
> closes all clients (cascades cleanup)
> NB.6!:3 (0.2)
> pD wsconnections_ws_ ; wssockets_ws_
> pD  'q0';wd 'ws query 0'
> pD  'q1';wd 'ws query 1'
> )
> 
> cocurrent 'z'
> deleteitem_z_ =:  {. , >:@[ }. ]
> defaults1 =: ([`]@.(0=#@>@[))
> defaults =: defaults1"0 0 f.
> fixlenx =: 1 : (':';'((#y) {. x) u y')
> iorinf =: (#@[ _:^:= i.)
> inl_z_ =: (cocurrent@] ".@] [)"1 0
> pD_z_ =:  1!:2&2
> 
> 
> 
> ----- Original Message -----
> From: bill lam <bbill....@gmail.com>
> To: "programm...@jsoftware.com" <programm...@jsoftware.com>
> Cc: 
> Sent: Wednesday, February 12, 2014 8:51:46 PM
> Subject: Re: [Jprogramming] Qt websockets and doevents
> 
> I agree with Raul, and uncomfortable to try your script. If your handler is 
> non-trivial you should define it inside a locale/class and export it to 
> z-locale.
> 
> result of any wd command is always a string, ever since wd was first 
> introduced some decades ago.
> 
> 13.02.2014, в 9:08, Pascal Jasmin <godspiral2...@yahoo.ca> написал(а):
> 
> > 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)
> >> 
> >> 
> >> 
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm

-- 
regards,
====================================================
GPG key 1024D/4434BAB3 2008-08-24
gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3
gpg --keyserver subkeys.pgp.net --armor --export 4434BAB3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to