Skip to content

Instantly share code, notes, and snippets.

@kraih
Created June 11, 2011 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kraih/1020509 to your computer and use it in GitHub Desktop.
Save kraih/1020509 to your computer and use it in GitHub Desktop.
use Mojo::UserAgent;
my $ua = Mojo::UserAgent->new;
$ua->websocket('ws://localhost:3000/echo' => sub {
my $tx = pop;
$tx->on(finish => sub { Mojo::IOLoop->stop });
$tx->on(message => sub {
my ($tx, $message) = @_;
print "$message\n";
});
$tx->send('Hi!');
});
Mojo::IOLoop->start;
use Mojolicious::Lite;
websocket '/echo' => sub {
my $self = shift;
$self->on(message => sub {
my ($self, $message) = @_;
$self->send("echo: $message");
});
};
app->start('daemon');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment