Reputation: 423
I am trying to send a TCP packet to a host and get a response and obviously not doing something right.
I've compared to many posts and even my Perl Cookbook and can't figure out where I'm going wrong. Very simply trying the following:
use strict;
use warnings;
use IO::Socket::INET;
$| = 1;
my $socket = new IO::Socket::INET (
PeerHost => '<the_host_name>',
PeerPort => '33792',
Proto => 'tcp'
);
unless($socket) {
print "couldn't connect to the server\n";
}
# data to send to a server
my $req = <<SBCEND;
START
AUTOLOGUE CENTRAL
TYPE|QUOTE|
H|1|1.0|Regular|CANCEL|6072|TESTDT|JOHNAIX| | |26000|DEMO| | | | | | | | |0
P|1|HAS|LF115|HAS|LF115|10| | | | | | | | | | | | | | |
P|2|WIX|51515|WIX|51515|24| | | | | | | | | | | | | | |
P|3|FRA|PH8A|FRA|PH8A|2| | | | | | | | | | | | | | |
END
SBCEND
my $message = "\002".$req."\003";
my $size = $socket->send($message);
shutdown($socket, 1);
my $response = "";
$socket->recv($response, 1024);
$socket->close();
print "sent: $size\n$req\n";
print "received response: $response\n";
I get no response at all, not sure if I'm supposed to or If something is wrong with my request.
When I ask their support if I'm supposed to get any response regardless, they send me the response I should receive from the docs if the request is valid.
The above request data is an example they sent to me. They did tell me I needed binary 2 at the beginning of my request and binary 3 after, hence my message variable above.
Can someone tell me if I'm doing something wrong here?
Upvotes: 1
Views: 1120
Reputation: 423
Turns out I needed a new line after the binary 2, a small change to this line:
my $message = "\002\r\n".$req."\003";
Upvotes: 1