Trihedralguy has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl use strict; #Create Socket Connection use IO::Socket::SSL qw(debug3); my $sock = IO::Socket::SSL->new( PeerAddr => 'LOCALHOST', PeerPort => '6999', SSL_version => 'SSLv3', SSL_cipher_list => 'COMPLEMENTOFDEFAULT', SSL_error_trap => 1 ); die "Could not create socket: " . IO::Socket::SSL::errstr() unless $so +ck; #Get the message my $socket_message = shift; print "Message Rec: $socket_message\n"; #Convert the hex message to a string $socket_message = (hex2string($socket_message)); print "Translated Message: $socket_message\n"; print "*Sending Message*\n"; print $sock $socket_message; print "*Message Sent*\n"; my $response; sleep 4; #I wish there was a better way to do this! #This times out the function so I can get everything from the server. $SIG{ALRM} = sub { die "timeout" }; eval { alarm(1); #Change this 1 to something else for more time. while(1){ sysread($sock, $response, 4000); } alarm(0); }; close($sock); print "Server Response: $response\n"; $response = (string2hex($response)); print "Server Response: $response\n"; print "Transaction Completed!"; #Hex Functions sub string2hex { my $in = shift; join(' ', map { sprintf("%02X", ord($_)) } split(//, $in)); } sub hex2string { my $in = shift; join('', map { &convert_word($_) } split(/\s+/, $in)); } sub convert_word { my $word = shift; my $rv = ''; if (length($word) == 2) { $rv = chr(hex($_)); } elsif (length($word) == 1) { $rv = $_; } $rv; } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Waiting for input, without sleep
by jrsimmon (Hermit) on Jun 30, 2009 at 14:54 UTC | |
by Trihedralguy (Pilgrim) on Jun 30, 2009 at 15:44 UTC | |
by jrsimmon (Hermit) on Jun 30, 2009 at 15:55 UTC | |
by Trihedralguy (Pilgrim) on Jun 30, 2009 at 16:12 UTC | |
by jrsimmon (Hermit) on Jun 30, 2009 at 16:28 UTC | |
| |
|
Re: Waiting for input, without sleep
by wol (Hermit) on Jun 30, 2009 at 17:10 UTC | |
|
Re: Waiting for input, without sleep
by pileofrogs (Priest) on Jun 30, 2009 at 19:50 UTC | |
|
Re: Waiting for input, without sleep
by ikegami (Patriarch) on Jun 30, 2009 at 15:54 UTC | |
by Trihedralguy (Pilgrim) on Jun 30, 2009 at 15:57 UTC | |
by ikegami (Patriarch) on Jun 30, 2009 at 16:02 UTC | |
by Trihedralguy (Pilgrim) on Jun 30, 2009 at 16:10 UTC | |
by ikegami (Patriarch) on Jun 30, 2009 at 19:00 UTC |