Hi
I am trying to achieve a fairly simple thing: I want to run a websocket server which is controlled by a main loop instead of the Async::Loop, like this:
my $sslSocket = IO::Socket::SSL->new( Listen => 5, LocalPort => XXX, Proto => 'tcp', SSL_startHandshake => 0, SSL_cert_file => 'XXX', SSL_key_file => 'XXX', ) or die "failed to listen: $!"; my $server = Net::Async::WebSocket::Server->new( on_client => sub { my ( undef, $client ) = @_; $client->configure( on_text_frame => sub { my ( $self, $frame ) = @_; $self->send_text_frame( $frame ); }, ); }, on_handshake => sub { my ( $self, $client, $hs, $continue ) = @_; $continue->( 1 ); } ); my $loop = IO::Async::Loop->new; $loop->add( $server ); $server->listen( handle => $sslSocket )->get;
In the main loop I am calling "$loop->loop_once" whenever the listening socket "$sslSocket" has data available, like this:
while(1){ // something before if (//data to read) { $loop->loop_once; } // something after }
Unfortunately the websocket connection is never established. None of the callbacks is called. I think I am getting the purpose of "loop_once" wrong but I don't know what the exact issue is.
I already tried to use $loop->run", then the connection can be established correctly. But this is not what I require. I need the main loop to take care of other tasks inbetween.
Thanks for help!
In reply to Net::Async::WebSocket::Server in a separate main loop by Talkabout
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |