Skip to content

Instantly share code, notes, and snippets.

@gabrielqmatos88
Forked from chankeypathak/chat_client.pl
Created November 16, 2016 13:34
Show Gist options
  • Save gabrielqmatos88/155fac069f6e8c5dc55ca52afe9ae3af to your computer and use it in GitHub Desktop.
Save gabrielqmatos88/155fac069f6e8c5dc55ca52afe9ae3af 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