Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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

In reply to Socket Newbie (perl newbie, too...) by Sabacthani

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2023-03-20 08:37 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (58 votes). Check out past polls.