Jeff Abrahamson on Mon, 20 May 2002 23:30:31 +0200 |
I'm writing a test harness for a program that talks tcp/ip. I just want some perl code that can listen on a socket, grab the bundles that come across, and write them to stdout (with appropriate translation) so I can monitor what's happening. I'm hitting a stumbling block that I think must be a minor misconception. What I'm expecting has the form (in C-speak) { char, short, /* this is N, below */ struct { long, long, long }[N] /* where N was read as the short after the char */ } So I write this thing that uses IO::Socket::INET and, after the new call, says $client = $inet->accept(); while(my $block = <$client>) { print_one($block); } Ah, but there's the rub. That read <$client> is looking for an EOL terminator, near as I can tell, but it probably won't get one, as what it's reading is binary. In C, I'd use read, which I could do in perl, too. But I expect perl to be simpler for such a simple case. Am I missing something? As an aside, is there a simple way to unpack that data struct that comes across? I'm currently using a sequence of unpacks, the first to get the char and the short (N), then others to read the array of structs. Thanks in advance for any tips. I'm a bit of a newbie for writing tcp/ip code. -- Jeff Jeff Abrahamson <http://www.purple.com/jeff/> The Big Book of Misunderstanding, now in bookstores and on the web: <http://www.misunderstanding.net/buystuff.html> Attachment:
pgpTtpVwxXOXz.pgp
|
|