-
-
Save gabrielqmatos88/155fac069f6e8c5dc55ca52afe9ae3af to your computer and use it in GitHub Desktop.
Simple chat client in Perl
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
#!/usr/bin/perl -w | |
# chat_client.pl | |
use strict; | |
use IO::Socket::INET; | |
my $port = shift or die "No port\n"; | |
my $server = shift or die "No server\n"; | |
my $client_socket = IO::Socket::INET->new( | |
PeerPort => $port, | |
PeerAddr => $server, | |
Proto => 'tcp' | |
) or die "Can't create send socket: $!!\n"; | |
my $child; | |
if($child = fork) { | |
while(1) { | |
sleep(1); | |
print scalar <$client_socket>; | |
} | |
} | |
die "fork failed!\n" unless defined $child; | |
print "Connected to $server:$port!\n"; | |
do { | |
print "> "; | |
print $client_socket $_ if defined $_; | |
} while(<STDIN>); | |
print "Closing connection"; | |
close $client_socket; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment