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

  • SEARCH
  • Home
  • 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 6895383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:54:06+00:00 2026-05-27T06:54:06+00:00

Its a simple Perl socket server. It listens for commands on a given port,

  • 0

Its a simple Perl socket server. It listens for commands on a given port, and executes an applescript if the command is ‘play’. There are two problems with the code below.

  1. Once the ‘play’ command is executed, both the client and the server are closed. (I want the server to continue listening for commands, be it ‘play’ or otherwise)
  2. The sockets don’t unbind. (I have to change the port number everytime I reuse it)

I’m using Terminal on a mac to execute the perl script, and telnet via terminal on another mac to trigger it.

#!/usr/bin/perl -w 
use warnings;
use IO::Socket; 
use Net::hostent;

$PORT = 8000;

    $server = IO::Socket::INET->new( Proto     => 'tcp',
                                     LocalPort => $PORT,
                                     Listen    => 5,
                                     Reuse     => 1) or die "can't setup server" unless $server;

    print "SERVER Waiting on port $PORT\n";

    while ($client = $server->accept()) { 
        $client->autoflush(1); 
        print $client "Command:\r\n";

        while (<$client>) {
            if (/play/i) { 
                exec("osascript '/Users/user/Desktop/play.app'");
            } else {
                print $client "invalid command\r\n";
            } 
        } continue { 
                        print $client "Command: "; 
        } close $client; 
    }
  • 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-27T06:54:06+00:00Added an answer on May 27, 2026 at 6:54 am

    You are using exec. From perldoc -f exec

    The exec function executes a system command and never returns; use
    system instead of exec if you want it to return. It fails and returns
    false only if the command does not exist and it is executed directly
    instead of via your system’s command shell (see below).

    Since it’s a common mistake to use exec instead of system, Perl warns
    you if there is a following statement that isn’t die, warn, or exit
    (if -w is set–but you always do that, right?). If you really want to
    follow an exec with some other statement, you can use one of these
    styles to avoid the warning:

    This basically means that your socket closes, because the perl script exits. I assume this leaves the ports blocked because the socket is never explicitly or implicitly closed.

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

Sidebar

Related Questions

My question is pretty simple: If you have two web-application components: Server-side (secret-capable) code
Well, I have a simple question, at least I hope its simple. I was
This really has my stumped today. I'm sure its simple, but... Here is my
Its a simple config app with 4 checkboxes and 5 textboxes, and all values
Its a simple question, but I'm not aware of the answer and I couldn't
I'm an IIS guy and know its as simple as just using the http://[computername]/path
I'm developing a desktop Mac OS X App that saves its very simple data
I have a class CollectionOfThings . As its name suggests its a simple collection
I am trying to implement the MVP pattern for WINFORMS. Its a simple for
I have simple regex \.*\ for me its says select everything between and ,

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.