Hello Monks! I had posted recently here asking about assistance with processing multiple perl files.

After much extensive research since then, I've come across various bidirectional socket server examples but so far none of them do what I need to do.

Is there some way that I could create or incorporate something that can various methods simultaneously while handling multiple clients at the same time (considered fork but I run into problems throughout.

These are the obstacles I need to overcome:

The workflow process I need to accomplish utilizes a SEND and RECEIVE method (our local server already has these methods established - my task is to create the other side of the connection) and follows this procedure:

I have attempted to create a single perl file (module?) called biclient.pl as a test. Ideally, what I had pictured in my mind was something along the lines of a forked server (to handle arbitrary number of simultaneous connections) that would behave differently depending on which IP address/hostname it was coming from:

#!/usr/bin/perl -w use strict; use warnings; use IO::Socket::INET; my $socket = IO::Socket::INET->new ( PeerHost => "X.X.X.X", PeerPort => "9000", LocalHost => "Y.Y.Y.Y", LocalPort => "9001", Listen => SOMAXCONN, Reuse => 1 ) or die "Can't connect to socket: $!\n"; while (my $client = $socket->accept) { my $pid = fork(); if ($client->peerhost() = X.X.X.X) if ($pid == 0) { handle_client($client) } ... }

My code fails my guess because it's trying to listen and connect a peer. Any help would be very much appreciated.


In reply to Bidirectional Client/Server - to fork or not to fork? by ljamison

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.