in reply to Client-Server Programme hangs...

I notice a few issues here: First of all, the sample output you gave us could not possibly be produced by the code you've showed us because it includes lines like DATA in $data slice 1 is THISISTHEEND which doesn't appear in your code. Second, in your current code you are creating a new socket for every input from the user. I'm not sure if this is what you want or not. The problem is, you never close these sockets. So here's the sequence that happens right now:
  1. Client receives a message from the usr
  2. Client opens socket with server
  3. Server accepts connection and begins listening for client data
  4. Client sends data and loops, waiting for response from server
  5. Server receives data and writes back to client with the word THISISTHEEND
  6. Client receives this message and ends the loop
  7. Client receives next input from the user
  8. Client opens new socket with the server
This socket will never be accepted because the client never closed the old one, and the server is still waiting for data on it.

Replies are listed 'Best First'.
Re^2: Client-Server Programme hangs...
by aodukoya (Initiate) on Dec 31, 2004 at 01:44 UTC
    The Sample output I gave was my initial script the one I posted was to reproduce the same issue with a smaller code, as the other code ran to about 4000 or more lines with some dbi connections and queries against the database.
    Why I am creating a new socket with every command entered by the user is also because I could not get the script to work with just one connection...as I explained above the main script does the following
    1. accept a users command
    2. parse the users command to see if the syntax is correct
    3. connect to a local oracle database and execute the relevant sql with regards to the command entered by the user
    4. go to a server that should have similar data based on an already defined hostname, oracle sid, username and password and check whether the same data is there
    5. report back to the user on the local host the results
    6. User now gets the prompt back and can enter new commands if wanted

    I have tried to put $socket->close ; in a varied number of places especially in the function that creates client connections but I am sure this did not fix the issue. I will test this out again and post my findings.
    Thanks for the tip.
      One other thing. Make sure you put $socket->autoflush() immediately after you create the socket at the client side, and $session->autoflush() immediately after you accept the connection on the server side. In your current code the proper place to do a $socket->close() would be after the return from host_to_user.
        Hello Errto,
        Thanks for your last suggestions I have implemented all that you said but it really did not help, to resolve the issue. It's still hanging...

        sub host_to_user { + my $nread ; my $inp ; $/ = CRLF ; while (<$socket>) { chomp; + my @data = split/-/, $_ ; print $_ , "\n"; print "The first value is $data[1]\n"; if ($data[1] eq 'THISISTHEEND') { $socket->close ; print " I have executed the close\n"; return 0 ; } } # + $socket->close ; #<- position 2 ###print " I have executed the close\n"; # return ; }

        The output is still the same the following is the output of the above code.

        $ ./client Testing> Hello I have received your message[server]-THISISTHEEND The first value is THISISTHEEND I have executed the close Testing> So what ^C$ $

        I even tried to put the $socket->close () in what I mentioned as position 2, but that was worse and the execution never got to the close section so I took it out.