Problem with socket code...help!
Posted on 2005-04-05
500 points for anyone who helps me with this! I am connecting to a server. I was told to use asynchronous sockets when creating this api.
Here is my code, it is actually not receiving anything from the server.
my $socket = new IO::Socket::INET (
PeerAddr => '10.0.0.2',
PeerPort => '2222',
Proto => 'tcp',
die "Could not create socket: $!\n" unless $socket;
#TaskID = 0xD0 - constant
#MsgSize = 40 - constant
#Client ID = 0;
#Status = 0;
#Command - Get number of stats counters = 0x65
#Reserved = 0;
#ChannelNum = 0
#Refresh = 0 (no refresh)
#1st Count Address = 0 ???
#Num of counters -
@requestBytes=(0xD0, 0x28, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x01);
$requestMsg = pack 'C*',@requestBytes;
#Retrieve only header
my ($taskid, $size, $clientId, $status, $command) = unpack "C4 C4 C4 C4 C4", $buffer;
if ($size >= $request_size)
my ($channelNum, $refresh, $ctAddress, $counter1, $counter2) = unpack "C4 C4 C4 C8 C8", $buffer;
print "channel num $channelNum\n";
#Parse data -
#Payload - each non-counter field 4 bytes = total length - 4*4+8*numCounter)