philiotis has asked for the wisdom of the Perl Monks concerning the following question:

I can write binary to a socket that successfully gets processed by the server. When the server replies, again in binary, my client hangs. I tried using echo to debugg but again the same issue (works fine with ASCII). Below is part of the code:
#!/opt/perl5/bin/perl use strict; use Socket; my $messageCounter = 0; my $message; my $reply; my $length; my $protocol = getprotobyname('tcp'); my $socketCreated; my $remoteHost = "XXXXXX"; my $packed_ip; my $remotePort = XXXX; my $portAddress; #BINARY OUTPUT FILE DEBUGGING ONLY my $binfilename = "BINARY_OUTPUT_FILE"; my $open_binName = sprintf(">%s", $binfilename); open(BIN_FILE, $open_binName) || die "can't open BIN_FILE: $!"; #Open Socket $socketCreated =socket(SocketHandle,PF_INET,SOCK_STREAM ,$protocol); $packed_ip = inet_aton($remoteHost); $portAddress = sockaddr_in($remotePort, $packed_ip); #Open Connection connect(SocketHandle, $portAddress) || die print "Could not Establish +a Connection\n"; print "Connection Successfully Established\n"; #enable buffering select((select(SocketHandle), $| = 1)[0]); $messageCounter++; $message = DCPLogin($messageCounter); # returns the binary string print SocketHandle $message; #hangs here while($length=sysread(SocketHandle, $reply, 1024)){ print BIN_FILE $reply; }#end while close(BIN_FILE) || die "couldn't close BIN_FILE: $!"; #debuggin +g only closeConn(); #function that closes the connection

Replies are listed 'Best First'.
Re: reading binary from a socket
by insensate (Hermit) on Nov 07, 2002 at 21:36 UTC
    What happens when you add the following line?
    open(BIN_FILE, $open_binName) || die "can't open BIN_FILE: $!"; binmode BIN_FILE;
      nothing I already tried that
Re: reading binary from a socket
by iburrell (Chaplain) on Nov 08, 2002 at 00:10 UTC
    What do you mean hangs? Does it reach the read loop? Or do you mean that it never exits? One problem could be that your server doesn't close the socket. The read loop won't exit until the socket is closed (and sysread returns zero). One way to check this is put a "print STDERR" inside the loop. Another is to unbuffer output to BIN_FILE and see if anything shows up in it.