Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Node JS Socket.IO server with perl

by mojo2405 (Acolyte)
on Jan 03, 2018 at 10:16 UTC ( #1206590=perlquestion: print w/replies, xml ) Need Help??
mojo2405 has asked for the wisdom of the Perl Monks concerning the following question:

Hi there, I would like to create a client in perl that can connect to node js server. I tried this code

use strict; use AnyEvent; use AnyEvent::PocketIO::Client; use PocketIO::Client::IO; #use PocketIO::Client::IO; my $socket = PocketIO::Client::IO->connect(""); my $cv = AnyEvent->condvar; my $w = AnyEvent->timer( after => 5, cb => $cv ); $socket->on( 'message', sub { say $_[1]; } ); $socket->on( 'connect', sub { #$socket->send('Parumon!'); $socket->emit( 'message', { name => 'name', message => 'msg emit' +} ); print "connected"; } ); $cv->wait;

but got this error :

28 {"code":0,"message":"Transport unknown"} 0 at /usr/local/share/perl5/AnyEvent/PocketIO/ line 86. Can't call method "transport" on an undefined value at +line 9.

can anyone help with that ?

Replies are listed 'Best First'.
Re: Node JS Socket.IO server with perl
by NetWallah (Canon) on Jan 04, 2018 at 01:59 UTC
    The error message about transport seems to be coming from your server at port 3001.

    Can you get a "tcpdump" to capture it ?

    Here is the code snippet (in AnyEvent::PocketIO::Client) that is catching the error:

    $socket->on_read( sub { return unless length $_[0]->rbuf; return if $read; my ( $status_line ) = $_[0]->rbuf =~ /^(.+)\015\012/; my ( $code ) = $status_line =~ m{^HTTP/[.01]+ (\d+) }; my $error; if ( $code && $code != 200 ) { $_[0]->rbuf =~ /\015\012\015\012(.*)/sm; $error = { code => $code, message => $1 }; $read++; $cb->( $error, $self ); #<<< Line # 86 <<<< return; }
    Since the "code" is displayed as "0" it is very strange that it it is passing the "if" check.

    I suspect the "$code" contains something like "00", which is later displayed as "0".

                    We're living in a golden age. All you need is gold. -- D.W. Robertson.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1206590]
Approved by marto
[Discipulus]: as a greed Agrid I agree.. coffee!

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2018-05-21 08:22 GMT
Find Nodes?
    Voting Booth?