Hi, I hope that this is a really silly newbie question, revolving around a simple mistake. (:
I'm trying to communicate with a data server, providing stock quotes and the like. I'm quite new to perl, and very new to socket programming, so I'm not entirely sure what I'm doing... I've been reading through the search results for a couple days, but I'm still stumped.
The header of each packet is in binary, followed by a bunch of ASCII data, in the format:
1 byte ascii sync byte (character 002)
2 byte message size (including header)
1 byte data offset (header size)
1 byte message type (To logon, I'm to send hex value 0x4c)
4 byte sequence id number
2 byte protocol id (always 0)
2 byte version number (1)
And then the ASCII data consisting of login and password information. I'm not sure if y'all will be able to help with this at all -- to many variables, I'm too lost... It might not even be a perl problem -- but I thought that if I posted the code someone might have some good advice. It complains that the message length is invalid -- am I not communicating the size correctly? Or am I doing something silly that makes the header much bigger than it should be? Thank you, and I'm sorry this is so involved...
#!/usr/bin/perl -w
use IO::Socket;
$rsock = new IO::Socket::INET (PeerAddr => 'blah',
PeerPort=> 1234,
Proto => 'tcp',
);
die "Remote socket could not be created: $!\n" unless $rsock;
$str[0]="\002";
$str[1] = unpack("B*", pack("N", 47));
$str[2] = unpack("B*", pack("N", 12));
$str[3] = unpack("B*", pack("N",76));
$str[4] = unpack("B*", pack("N", 1));
$str[5] = unpack("B*", pack("N", 0));
$str[6] = unpack("B*", pack("N", 1));
$header=join('',@str);
$header=$header."LOGON USERNAME=NAME PASSWORD=PASS\0";
print $rsock $header;
#syswrite($rsock,$header,47);
# Print, or syswrite? Neither seem to help...
while (<$rsock>) {
last unless /\S/;
chomp;
print;
}
# Returns Error: Ileagle message size in header
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.