in reply to Re: Bidirectional Client/Server - to fork or not to fork?
in thread Bidirectional Client/Server - to fork or not to fork?

Your proxy code is totally broken.

First, you only ever accept one connection:

my $client = $sock->accept();

As this is outside of any loop, you'll never even attempt to accept a second or subsequent connection.

And then, you never attempt to read anything from the connecting client:

while(){ while ($client) {

The first line is an endless loop. The second line continues to loop whilst the variable $client has some value; which it always will, which means it is also and endless loop.

In the body of that loop, you are test $_ for the strings ADD and STK, but since you've never read anything from the client, $_ will never get any value, so neither string will be found and no action will ever be taken.

Effectively, your entire program accepts one connection and then loops endlessly doing nothing.

So quite how that "results in a connection refused message" is a mystery seeing as you are never even attempting to connect to the Windows machine?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^3: Bidirectional Client/Server - to fork or not to fork?
by ljamison (Sexton) on Dec 08, 2015 at 12:54 UTC

    BrowserUk, thank you for jump starting my critical thinking! I see what I did wrong now thanks to you!

    When you pointed out about how I accept only one connection into an endless loop it made me realize what I did wrong so I changed the following and, from what I can tell so far, it appears to be working so thank you for your criticisms!!!!

    # I ended up changing this my $client = $sock->accept(); # and this while() { while ($client) { . . . } # to this my $client; # and this while() { while ($client = $sock->accept) { . . . }
    and now it works for every request I tried so far! Thank you BrowserUk!

      That still means that you aren't reading anything from the connecting client.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
Re^3: Bidirectional Client/Server - to fork or not to fork?
by Anonymous Monk on Dec 08, 2015 at 11:58 UTC

    I never intend to connect directly to the machine from the module above. The module above is intended only to be a "processing center" if you will. Let's call this module above module B and the Windows machine module C.

    A client, module A, connects to module B and sends a message of value "STK" to module B. Module B accepts the connection, performs pattern matching to determine what kind of message it is and passes it to the appropriate sub, and closes the socket. Then module B should go back to listening after it passes. The module B sub should connect to module C and send the message, then close the connection with C.