Basic non-Lite WebSocket Application

49 views
Skip to first unread message

john

unread,
May 15, 2016, 12:17:47 PM5/15/16
to mojol...@googlegroups.com
I have written mojo lite based websocket applications but am having
problems with my first attempt at a full application:

https://github.com/john-/mojo_inotifier

Here is what happens::

morbo script/inotifier
Server available at http://127.0.0.1:3000
[Sun May 15 10:57:08 2016] [debug] GET "/"
[Sun May 15 10:57:08 2016] [debug] Routing to controller
"Inotifier::Controller::Actions" and action "base"
[Sun May 15 10:57:08 2016] [debug] Rendering template "base.html.ep"
[Sun May 15 10:57:08 2016] [debug] Template "layouts/default.html.ep"
not found
[Sun May 15 10:57:08 2016] [debug] 200 OK (0.006929s, 144.321/s)
[Sun May 15 10:57:08 2016] [debug] GET "/wsinit"
[Sun May 15 10:57:08 2016] [debug] Routing to controller
"Inotifier::Controller::Actions" and action "wsinit"
[Sun May 15 10:57:08 2016] [error] Can't call method "app" on an
undefined value at lib/Inotifier/Controller/Actions.pm line 15, <DATA>
line 2231.

[Sun May 15 10:57:08 2016] [debug] Template
"exception.development.html.ep" not found
[Sun May 15 10:57:08 2016] [debug] Template "exception.html.ep" not found
[Sun May 15 10:57:08 2016] [debug] Rendering template
"mojo/development.html.ep"
[Sun May 15 10:57:08 2016] [debug] Rendering template "mojo/mojobar.html.ep"
[Sun May 15 10:57:08 2016] [debug] 500 Internal Server Error (0.035149s,
28.450/s)

in wsinit $self for this route is undef. This means to me I am doing
something wrong with my route definition:

$r->websocket('/wsinit')->to(controller => 'actions', action =>
'wsinit');

I tried alternate ways such as
"$r->websocket('/wsinit')->to('actions#wsinit');" with the same result.

What am I missing here?

Thanks,

John

Heiko Jansen

unread,
May 15, 2016, 1:22:51 PM5/15/16
to Mojolicious
Am Sonntag, 15. Mai 2016 18:17:47 UTC+2 schrieb john:
I have written mojo lite based websocket applications but am having
problems with my first attempt at a full application:

     https://github.com/john-/mojo_inotifier

Try changing Actions.pm, L13 from
my $self => shift;
to
my $self = shift;
?

john

unread,
May 15, 2016, 1:43:20 PM5/15/16
to mojol...@googlegroups.com


On 05/15/2016 12:22 PM, Heiko Jansen wrote:

Try changing Actions.pm, L13 from
my $self => shift;
to
my $self = shift;

Oh my goodness.   That was it.

Thanks,

John

Dotan Dimet

unread,
May 16, 2016, 10:42:58 PM5/16/16
to mojol...@googlegroups.com
Hi,
Sent you edits in github.
Looks like $self is undef because you have a typo when setting it in wsinit().
Also, looking at the docs it seems websocket() just creates a GET handler for the initial websocket handshake, if you want to actually send anything, you need to subscribe to a "message" event in your action.



On 15/05/16 19:17, john wrote:
I have written mojo lite based websocket applications but am having problems with my first attempt at a full application:

    https://github.com/john-/mojo_inotifier

Here is what happens::

morbo script/inotifier
[Sun May 15 10:57:08 2016] [debug] GET "/"
[Sun May 15 10:57:08 2016] [debug] Routing to controller "Inotifier::Controller::Actions" and action "base"
[Sun May 15 10:57:08 2016] [debug] Rendering template "base.html.ep"
[Sun May 15 10:57:08 2016] [debug] Template "layouts/default.html.ep" not found
[Sun May 15 10:57:08 2016] [debug] 200 OK (0.006929s, 144.321/s)
[Sun May 15 10:57:08 2016] [debug] GET "/wsinit"
[Sun May 15 10:57:08 2016] [debug] Routing to controller "Inotifier::Controller::Actions" and action "wsinit"
[Sun May 15 10:57:08 2016] [error] Can't call method "app" on an undefined value at lib/Inotifier/Controller/Actions.pm line 15, <DATA> line 2231.

[Sun May 15 10:57:08 2016] [debug] Template "exception.development.html.ep" not found
[Sun May 15 10:57:08 2016] [debug] Template "exception.html.ep" not found
[Sun May 15 10:57:08 2016] [debug] Rendering template "mojo/development.html.ep"
[Sun May 15 10:57:08 2016] [debug] Rendering template "mojo/mojobar.html.ep"
[Sun May 15 10:57:08 2016] [debug] 500 Internal Server Error (0.035149s, 28.450/s)

in wsinit $self for this route is undef.   This means to me I am doing something wrong with my route definition:

    $r->websocket('/wsinit')->to(controller => 'actions', action => 'wsinit');

I tried alternate ways such as "$r->websocket('/wsinit')->to('actions#wsinit');"  with the same result.

What am I missing here?

Thanks,

John



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Reply all
Reply to author
Forward
0 new messages