I am trying to program a client-server utility. which on the client checks the code entered and does some checks against an oracle database if the user so desires. My stand alone script works perfectly well on a local system. But I want to be able to check the data against other databases on the network: The problem is I am able to issue and confirm one command alone any other thing that I try and the script hangs...
I have tried using the non blocking code but this had no effect
i) Stand alone output
$ ./tester -local + Starting up the test util in single user mode ... + TestUtil>qry chk table testa + TESTA .............................Table Exists(ok) + TestUtil>qry chk table testb + TESTB .............................Table Exists(ok) + TestUtil>dml upd table testb + The where clause on testb is based on where object_id equals, please g +ive a valid value: 90 UpdTab> The sql is update testb set object_name = 'Shareplex' where ob +ject_id = ? The value entered is 90 + The number of rows Updated from testb is 1 + TestUtil>qry chk data testb + The total number of rows for testb is 82 + The number of modified rows are 2 + TestUtil> TestUtil>quit

ii) With network enabled
$ ./tester -local Starting up the test util with network enabled... TestUtil>ddl drp table testa I have received your message[server]-THISISTHEEND DATA in $data slice 1 is THISISTHEEND I have received your message[server]-THISISTHEEND DATA in $data slice 1 is THISISTHEEND TestUtil>ddl create table testa <-it hangs and I have to ctrl+C out

I created a little code to try to reproduce What I want to try to do as the whole code can't be posted, but this reflects the error perfectly well.
Also I noticed if I hash out the section on the client that tries to receive the message from the source all works well.
Client Code-Example
#!/usr/bin/perl + use warnings; use strict; use IO::Socket qw(:DEFAULT :crlf); my $port = $ENV{CM_PORT} || 3013 ; my $host = $ENV{CM_HOSTS} || 'uksupu02' ; my $read ; my $quit ; my $utilprmpt = 'Testing> '; my $socket ; my $user_input = 'start' ; RERUN_PROMPT: while ( $user_input ne 'quit') { + print "$utilprmpt"; + chomp ( $user_input = <>); + if (!$user_input){next RERUN_PROMPT } ; if ($user_input =~/^\s+$/){ next RERUN_PROMPT } ; if ( $user_input eq 'quit') { exit }; &CreateClient ; + } + + sub CreateClient { + $socket = IO::Socket::INET->new("$host:$port") or die "can't create s +ocket: $!"; user_to_host ($socket, $user_input) ; + &host_to_user ($socket); + } + sub user_to_host { + my $sock = shift; + my $msg = shift ; + print $sock $msg ,CRLF; + } + sub host_to_user { + my $sock = shift ; + my $nread ; + my $inp ; + $/ = CRLF ; + while (<$sock>) { + chomp; + my @data = split/-/, $_ ; + print $_ , "\n"; + if ($data[1] eq 'THISISTHEEND') { + return ; + } + } + }

iii) Server code
#!/usr/bin/perl + use warnings; use strict; use IO::Socket qw(:DEFAULT :crlf) ; my $port = $ENV{CM_PORT} || 3013 ; + my $quit = 0 ; my $session ; my $sock ; $SIG{INT} = sub { $quit++ } ; sub server { $sock = IO::Socket::INET->new( Listen => 5, LocalPort => + $port, Timeout => 60*60, Reuse => 1 ) or die "Can't create li +stening socket: $!\n"; warn "Waiting for incoming connections on port $port...\n"; + } &server ; + while ( !$quit ) { + next unless $session = $sock->accept; my $pport = $session->peerport; my $paddr = $session->peeraddr; my $pname = gethostbyaddr($paddr, AF_INET); my $peer = "$pname:$pport" ; warn "Connection from [$peer]\n"; while (<$session>){ chomp; my $msg_recv = $_ ; my $msg_out = ("I have received your message[server]-THISIS +THEEND") . CRLF ; print $session $msg_out ; print " Received=> $msg_recv \n"; } + warn "Connection from [$peer] finished\n"; close $session ; + }

Edited by theorbtwo: Moved from a reply to New user scratch pad. to a root SoPW.


In reply to Client-Server Programme hangs... by aodukoya

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.