Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6803231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:19:10+00:00 2026-05-26T19:19:10+00:00

My OS is Archlinux with perl 5.14.2. I am just trying to write a

  • 0

My OS is Archlinux with perl 5.14.2. I am just trying to write a little program to accomplish a remote comlile. The program just passes a C source file to the server. The server will call gcc to compile the C code and pass the compiler’s message. The client can’t receive the compiler’s message. I have the message in the server.
There is the code:

#!/usr/bin/perl -w
# oj.pl --- alpha


use warnings;
use strict;
use IO::File;
use IO::Socket;

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 "argh";         # 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;
    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`;

    foreach ( @lines) {
        print $session  $_ . "test!!!\n";
     #   $session->print;
    }


    print "OK!";
    $tmpFileToBeCompiled->close;

    warn "Connecting finished!\n";
    $session->close;
    $tmp --;
}

$sock_server->close;

----------------------------------------end--------------------------------------------------------
-------------------------------------client.pl--------------------------------------------------------
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");

my $child = fork();
die "Can't fork: $!\n" unless defined $child;

# if (!$child) {
#     $SIG{CHLD} = sub { exit 0 };
#     userToHost();
#     print "Run userToHost done!\n";

#     $socket->shutdown(1);
#     sleep;
# } else {
#     hostToUser();
#     print "Run hostToUser done! \n";

#     warn "Connection closed by foreign host\n";

# }
userToHost();
unless ($child) {
    hostToUser();
    print "Run hostToUser done! \n";
    warn "Connection closed by foreign host\n";
    $socket->close;

}

sub userToHost {
    while (<$fh>) {
#    print $_;    # for debug
    print $socket $_;
    }
}

sub hostToUser {
    while (<$socket >) {
    print $_;    
    }
}
# copy ("a.c", $socket) or die "Copy failed: $!";
print "Done!";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:19:10+00:00Added an answer on May 26, 2026 at 7:19 pm
    1. You don’t need to fork in client. At all. Just like themel said
    2. You have error in client code: <$socket > should be <$socket>
    3. You need to notify server that you have written all data and server can start compilation. Otherwise server will stuck at while (<$session>) forever.
      To achieve this you could call shutdown($socket, 1) which means you finished writing. See perldoc -f shutdown

    Final prototype (very rough) could look like this: https://gist.github.com/19b589b8fc8072e3cfff

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just installed Sphinx (distro: archlinux) downloading the source. Then I installed Thinking Sphinx
I’m trying to set up Jenkins on a RackSpace ArchLinux Cloud Server, but I’ve
I've got a little Problem with SDL: When starting my Program (on Archlinux 64bit),
I am trying to patch dmenu with the files provided here: http://aur.archlinux.org/packages.php?ID=27334 I do
I'm using drscheme from: http://www.archlinux.org/packages/extra/x86_64/drscheme/ I'm trying to work with the sample code in
I have been trying to write a simple mention grabber to get started with
I'm trying out the coffee script repl inside Emacs (under ArchLinux) and I'm seeing
There is a program named cower . ( cower is an Archlinux AUR downloader.)
I'm confronted with some problems when trying to configure gitosis on my Archlinux http://wiki.archlinux.org/index.php/Setting_Up_Git_ACL_Using_gitosis
Ok, just so you know, I haven't worked with dbus or perl much, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.