Skip to content

Instantly share code, notes, and snippets.

Created January 14, 2013 02:59
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 anonymous/d9edb0871e19d2f915b5 to your computer and use it in GitHub Desktop.
Save anonymous/d9edb0871e19d2f915b5 to your computer and use it in GitHub Desktop.
class Pr1::Conn {
has IO::Socket::INET $!conn;
method new ($conn) {
return self.bless(*, :$conn)
}
method send (Cool $str as Str) {
say $!conn.WHAT;
$!conn.send($str ~ "\r\n")
}
method readline() {
$!conn.readline;
}
method go () {
self.send("Welcome to Kevin Tew's Chat Server");
}
}
class Pr1 {
has $!listener;
has Int $.port = 9020;
has Str $.host = "localhost";
method connect (:$port=$.port, :$host=$.host)
{
$!listener = IO::Socket::INET.new(
:localhost($host),
:localport($port),
:listen(1)
);
$!listener.input-line-separator = "\r\n";
say "Hello Mom"
}
method handle()
{
loop {
my Pr1::Conn $a = Pr1::Conn.new($!listener.accept());
$a.go();
}
}
}
my $foo = Pr1.new;
$foo.connect();
$foo.handle();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment