Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TCP Protocol Tutorial?

Status
Not open for further replies.

Kirsle

Programmer
Jan 21, 2006
1,179
US
When I read over some docs of various TCP protocols (such as the MSN Messenger 6 protocol at hypothetic.org), they tend to mention things which I'm not quite sure how to implement in Perl.

For example, the MSN docs outline two types of messages sent, one-liners and payload commands which have multiple lines of data.

The one-liner commands seem pretty straightforward; they're sent in just one line, such as this one sent from the client to specify the version of the protocol it wants to use:

Code:
VER 0 MSNP8 CVR0\r\n

But this is an example of a payload command:

Code:
MSG 4 N 133\r\n
MIME-Version: 1.0\r\n
Content-Type: text/plain; charset=UTF-8\r\n
X-MMS-IM-Format: FN=Arial; EF=I; CO=0; CS=0; PF=22\r\n
\r\n
Hello! How are you?

According to the docs, the "133" at the end of the first line specifies the length of the following data. The recipient of this message should read in 133 bytes, no more and no less, to get the full content of the message sent. If it reads too many, it might accidentally read the first bytes of the next command, or if it reads too few it might cause an error with the next command received.

The docs I've found on using IO::Socket all specify to use read() or sysread() to read in data from the socket. These commands seem to require a number of bytes to read in.

I've played with various socket scripts, and for the most part, reading in a large number of bytes such as 2048, works in most cases.

Does anybody know of a good tutorial that specifies exactly how you're supposed to read in bytes? Like, according to the MSN protocol docs, Perl may have a way to read in a whole single line of data without specifying the number of bytes to read (since single one-liner commands don't specify their lengths), so it could find the length of additional bytes to read to get the entire payload command.

I've done some work using POE::SocketFactory and other similar POE socket modules, and these seem to do all the work for me. The handlers I set up simply receive a message from the other end of the socket and that's that. But I'd rather know how to do it at a lower level with IO::Socket.

Thanks in advance.
 
No, I wasn't asking specifically about MSN, just about TCP protocols in general and how to handle bytes. I use an unofficial module called MSN.pm to connect to MSN (last time I checked Net::Msmgr didn't work anyway, it had tons of syntax errors in its code like its creator wrote it but didn't test it).

So I'm looking for a tutorial on how to receive bytes on a TCP protocol.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top