Skip to content

Instantly share code, notes, and snippets.

@chankeypathak
Last active August 24, 2018 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chankeypathak/1b1b9b3a27799eb5e277 to your computer and use it in GitHub Desktop.
Save chankeypathak/1b1b9b3a27799eb5e277 to your computer and use it in GitHub Desktop.
Simple chat client in Perl
#!/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