Skip to content

jegade/plack-middleware-socketio

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Plack::Middleware::SocketIO

Plack::Middleware::SocketIO is a server implmentation 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::Builder;
use Plack::App::File;
use Plack::Middleware::Static;
use Plack::Middleware::SocketIO;

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

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

        enable "SocketIO", 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'});
        };

        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 middleware is in a very beta stage. API will be probably changed.

CREDITS

Socket.IO author(s) and contributors.

AUTHOR

Viacheslav Tykhanovskyi, [email protected].

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

About

Socket.IO Perl/Plack implementation

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Perl 100.0%