-
-
Save yko/19b589b8fc8072e3cfff 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
#!/usr/bin/env perl | |
use warnings; | |
use strict; | |
use IO::Socket qw(:DEFAULT); | |
use File::Copy; | |
use constant MY_TRAN_PORT => 138000; | |
use IO::File; | |
my $host = shift || '127.0.0.1'; | |
my $port = shift || MY_TRAN_PORT; | |
my $socket = IO::Socket::INET->new("$host:$port") or die $@; | |
my $fh = IO::File->new("a.c", "r"); | |
while (<$fh>) { | |
print $_; # for debug | |
print $socket $_; | |
} | |
shutdown($socket, 1); | |
while (<$socket>) { | |
print " > $_"; | |
} | |
$socket->close; | |
print "Done!\n"; |
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/env perl | |
use warnings; | |
use strict; | |
use IO::File; | |
use IO::Socket; | |
use Time::HiRes 'sleep'; | |
use constant MY_TRAN_PORT => 138000; | |
$| = 1; | |
my $tmpFileToBeCompiled = IO::File->new("> tmpFile09090989.c") | |
or die "Can't creat this file"; | |
#if (defined $tmpFileToBeCompiled) { | |
# print $tmpFileToBeCompiled "fuck"; # just for test! | |
#} | |
# $fihi->close; | |
my $port = shift || MY_TRAN_PORT; | |
my $sock_server = IO::Socket::INET->new( | |
Listen => 20, | |
LocalPort => $port, | |
Timeout => 60, | |
Reuse => 1 | |
) or die "Can't create listening socket: $!\n"; | |
my $tmp = 1; | |
while ($tmp) { | |
next unless my $session = $sock_server->accept; | |
my $peer = gethostbyaddr($session->peeraddr, AF_INET) | |
|| $session->peerhost; | |
print $session "test!\n"; | |
warn "Connection from [$peer, $port]\n"; | |
while (<$session>) { | |
print $tmpFileToBeCompiled $_ | |
; # if it works, the filehandle should be changed into tmpFile. just fixed. | |
print $session "test!"; | |
} | |
my @lines = `gcc tmpFile09090989.c 2>&1`; | |
warn "Result: " . join "", @lines; | |
foreach (@lines) { | |
print $session $_ . "test!!!\n"; | |
# $session->print; | |
} | |
print "OK!"; | |
$tmpFileToBeCompiled->close; | |
warn "Connecting finished!\n"; | |
$session->close; | |
sleep 0.2; | |
} | |
$sock_server->close; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment