Last active
August 24, 2018 14:36
-
-
Save chankeypathak/1b1b9b3a27799eb5e277 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