Home Website Changes Log in Log out

Chat Tutorial

Videos

I've put together a tutorial for building a multi-user chat application. It's broken into 4 parts, starting from an empty file and eventually getting to a fancy AJAX/COMET based multi-user chat. I'm not following a script or anything, which makes the pace of the videos casual and detailed.

Part 1 of 4 (5:34) -- Hello, Joe!

Final code:

#!/usr/bin/perl

use strict;
use Continuity;

$server = Continuity->new( port => 8080 );
$server->loop;

sub main {
  my ($request) = @_;
  $request->print(qq{
    <form>
      Name:
      <input type=text name=name>
    </form>
  });
  $request->next;
  my $name = $request->param('name');
  $request->print("Hello, $name!");
}

Part 2 of 4 (12:49) -- Chat

Final code:

#!/usr/bin/perl

use strict;
use Continuity;

my @messages;

my $server = Continuity->new( port => 8080 );
$server->loop;

sub main {
  my ($request) = @_;
  my $name;
  while(1) {
    $request->print(qq{
      <form>
        Name: <input type=text name=name
          value="$name"><br>
        Message: <input type=text name=msg size=40>
        <input type=submit value="Send">
      </form>
    });
    $request->print(join '<br>', reverse @messages);
    $request->next;
    $name = $request->param('name');
    my $msg = $request->param('msg');
    push @messages, "$name: $msg" if $msg;
  }
}

(and the rough plan for parts 3 and 4 ...)

Part 3 of 4 -- AJAX Chat

Part 4 -- COMET Chat