-
-
Save anonymous/d9edb0871e19d2f915b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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