philiotis has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 | |
by philiotis (Initiate) on Nov 07, 2002 at 23:18 UTC | |
|
Re: reading binary from a socket
by iburrell (Chaplain) on Nov 08, 2002 at 00:10 UTC |