/pocketio

SocketIO Plack App

Primary LanguagePerl

PocketIO

PocketIO is a server implementation of SocketIO in Perl.

All the transports are supported.

WebSocket
Adobe® Flash® Socket
AJAX long polling
AJAX multipart streaming
Forever Iframe
JSONP Polling

SocketIO

More information about SocketIO you can find on the website http://socket.io/, or on GitHub https://github.com/LearnBoost/Socket.IO.

EXAMPLE

Below is an example similar to Socket.IO-node example chat. To run this example, you need to make the following simple steps:

1. Clone somewhere https://github.com/LearnBoost/Socket.IO-node.
2. Save the shown .psgi file, changing <$path_to_socket_io> so it points to the Socket.IO-node files.
use Plack::App::File;
use Plack::Builder;
use Plack::Middleware::Static;

use PocketIO;

my $path_to_socket_io = "/path/to/Socket.IO-node";

builder {
    mount '/socket.io/socket.io.js' => Plack::App::File->new(
        file => "$path_to_socket_io/support/socket.io-client/socket.io.js");

    mount '/socket.io' => PocketIO->new(
        handler => sub {
            my $self = shift;

            $self->on_message(
                sub {
                    my $self = shift;
                    my ($message) = @_;

                    $self->send_broadcast(
                        {message => [$self->id, $message]});
                }
            );

            $self->on_disconnect(
                sub {
                    $self->send_broadcast(
                        {announcement => $self->id . ' disconnected'});
                }
            );

            $self->send_message({buffer => []});

            $self->send_broadcast(
                {announcement => $self->id . ' connected'});
        }
    );

    mount '/' => builder {
        enable "Static",
          path => qr/\.(?:js|css|jpe?g|gif|png|swf|ico)$/,
          root => "$path_to_socket_io/example";

        enable "SimpleLogger", level => 'debug';

        sub {
            [   200,
                ['Content-Type' => 'text/html'],
                ['Open <a href="/chat.html">chat</a>.']
            ];
        };
    };
};
3. Start Twiggy or Fliggy (same as Twiggy but with inlined Flash Policy server)
$ sudo flash-policy-server &
$ twiggy chat.psgi --listen :8080

or

$ fliggy chat.psgi --listen :8080
4. Point your browser to
http://localhost:8080

TLS/SSL

For TLS/SSL a secure proxy is needed. stunnel or App::TLSMe is recommended.

DISCLAIMER

This application is in a very beta stage. API will be probably changed.

CREDITS

Socket.IO author(s) and contributors.

AUTHOR

Viacheslav Tykhanovskyi, vti@cpan.org.

COPYRIGHT

Copyright (C) 2011, Viacheslav Tykhanovskyi

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

POD ERRORS

Hey! The above document had some coding errors, which are explained below:

Around line 11:

Non-ASCII character seen before =encoding in 'Adobe®'. Assuming UTF-8