in reply to Re: Sending ASCII Control Chars over TCP/IP socket
in thread Sending ASCII Control Chars over TCP/IP socket

Somehow it's working:
#!/usr/bin/perl use IO::Socket; use strict; my( $socket,$ret ); my $maxlen = 1024; my $timeout = 5; # my $data = "\x02H\x04"; # getVersion <STX>CMD<EOT> my $data = "\x02LS9F\x04"; # getSerial <STX>CMD<CHECKSUM><EOT> $socket = IO::Socket::INET->new ( PeerAddr => '192.168.1.16', PeerPort => 10001, Proto => 'tcp' ) or die "ERROR in + Socket Creation : $!\n"; main::printdata('Client sends',$data ); $socket->send($data) or die "send: $!"; $socket->recv( $ret,$maxlen ); main::printdata('Server responded',$ret ); $socket->close();
Result:
Client sends \x02LS9F\x04
Server responded \x0200000000030000000000C3\x04

But when I add $socket->recv( $ret,$maxlen ) or die "Fail: $!"; the cmd always fails. with an empty error:
Client sends \x02LS9F\x04
Fail:

How do I increase the verbosity level to find out what's going wrong here?

Replies are listed 'Best First'.
Re^3: Sending ASCII Control Chars over TCP/IP socket
by hippo (Archbishop) on Jun 30, 2019 at 10:05 UTC
    How do I increase the verbosity level to find out what's going wrong here?

    Item 1 in the Basic debugging checklist suggests to use warnings which you are not doing here. Enable that for starters.

    $socket->recv( $ret,$maxlen ) or die "Fail: $!";

    The docs for recv say:

    Returns the address of the sender if SOCKET's protocol supports this; returns an empty string otherwise. If there's an error, returns the undefined value.

    But your statement only tests for truth rather than definedness. Try this instead, perhaps:

    $socket->recv( $ret,$maxlen ) // die "Fail: $!";