Perl Sockets - Raw Data

I am using a modified sample script to capture udp packets on a single port and then send the data back to the sender. This seems to work fine. My issue is that the payload being sent seems to be converted to ascii. Anything that I have tried converts the data to ascii then back to hex, something gets lost in translation. What I need is the original message as it is sent.  Thanks

Sample packet data

8305123100138201010102034c4b28ead64b28ead618a74dd4d422467a00003c4d0000002101170620001affab0f280f0005030200000000000000c594




#!/usr/bin/perl -w
# udpqotd - UDP message server
use strict;
use IO::Socket;

my($sock, $newmsg, $hisaddr, $MAXLEN, $PORTNO);
$MAXLEN = 1024;
$PORTNO = 21210;
$sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp' )
    or die "socket: $@";
print "Awaiting UDP messages on port $PORTNO\n";

while ($sock->recv($newmsg, $MAXLEN)) {
    my($port, $ipaddr) = sockaddr_in($sock->peername);

    print "This: $newmsg \n" ;
    $sock->send($newmsg);
}
die "recv: $!";

Open in new window

altobravoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TobiasCommented:
Dear,

I have tried your code with a client, and I didn't see any problem. Maybe it's the receiver that corrupt the data. I send you the client used (the server was the perl code that you provided)  then maybe you could find something that will help you.

Best Regards
#!/usr/bin/perl -w
# udpmsg - send a message to the udpquotd server

use IO::Socket;
use strict;

my($sock, $server_host, $msg, $port, $ipaddr, $hishost, 
   $MAXLEN, $PORTNO, $TIMEOUT);

$MAXLEN  = 1024;
$PORTNO  = 21210;
$TIMEOUT = 5;

$server_host = shift;
$msg         = "8305123100138201010102034c4b28ead64b28ead618a74dd4d422467a00003c4d0000002101170620001affab0f280f0005030200000000000000c594";
$sock = IO::Socket::INET->new(Proto     => 'udp',
                              PeerPort  => $PORTNO,
                              PeerAddr  => 'localhost')
    or die "Creating socket: $!\n";
$sock->send($msg) or die "send: $!";

eval {
    local $SIG{ALRM} = sub { die "alarm time out" };
    alarm $TIMEOUT;
    $sock->recv($msg, $MAXLEN)      or die "recv: $!";
    alarm 0;
    1;  # return value from eval on normalcy
} or die "recv from $server_host timed out after $TIMEOUT seconds.\n";

($port, $ipaddr) = sockaddr_in($sock->peername);
$hishost = gethostbyaddr($ipaddr, AF_INET);
print "Server $hishost responded ``$msg''\n";

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.