Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Listening UDP socket

Reply
Thread Tools

Listening UDP socket

 
 
jussi
Guest
Posts: n/a
 
      04-11-2006
Hi gurus

My program listen a socket and wait for right kind of string to do a
job. Problem is that some times the string cut out and my program
thinks that all the data is arrived and we can continue.

Here is part of my program:

------------------ SNIP ----------------------------------------------


$MySocket=new IO::Socket::INET->new(LocalPort=>3500,Proto=>'udp');

while(1)
{
$MySocket->recv($ID,12;
print LOG "data to socket: $ID\n";
# print to LOG every data what get to socket
if ($ID =~ /1820/)
# does the string contain numbers 1820, if yes go on
{
print LOG "We are in with string: $ID\n";
$ID =~ s/.*10([1-9])00//;
#cut garpage out
$ID =~ s/\W+\D+//;
# only numbers and letters
$ID =~ s/[a-z]//;
# delete these too
$ID =~ s/${1}//;
# cut last mark out because it's usually garpage
$ID =~ /([A-F0-9]{1,16})/;
#I should have 1-16 numbers or letters
print LOG "to HEX2ASCII: $ID\n";
#print to LOG before translate
$h_str = pack 'H*', $ID;
# HEX2ASCII
Print LOG "from HEX2ASCII: $h_str\n";
# print to log after translate




------------------------- SNIP
------------------------------------------


OK. So my script listening a UDP socket and waits for a string which
contains a string 1820. This usually work. But some times the string
some how cuts out and rest of my script get faulty string to proces.

Here is part from my LOG to show what I mean. First part is how it
ususally works (and should work)

------------- SNIP --------------------------------

data to socket: ë
data to socket: ì
data to socket: í
data to socket: î
data to socket: ï
data to socket: ð
data to socket
: ñ
data to socket: ò
data to socket: ó
data to socket: ô
data to socket: õ
data to socket: ö
data to socket: ÷
data to socket: ø
#all this is gargabe
so do nothing
data to socket: ù0184000100000182000106004D3737363034ß
# here is right kind of string so go on
We are in with string: ù0184000100000182000106004D3737363034ß
#So we are in
to HEX2ASCII 4D3737363034
# take out constant header
and send only the part we are intrested
from HEX2ASCII: M77604
# yes, hex2ascii is working
right
data to socket: ú
# lets wait next right
header
data to socket: û
data to socket: ü018300010000
# thsi string is not what we want
so do nothing

data to socket: ý
data to socket: þ
data to socket: ÿ
data to socket:
data to socket:
data to socket:
data to socket:


------------------------------ SNIP ---------------------------------


And next SNIP from LOG is my problem:

------------------------------- SNIP
-----------------------------------


data to so socket:
data to so socket:

data to so socket:

data to so socket:
data to so socket: # so
far its empty or garbage
data to so socket: 01840001000001820 # yes, here is
string with 1820 which we are intrested, but this is header part were
is the REAL part we want to ??
We are in with string:: 01840001000001820 # so we take it to
for processing
to HEX2ASCII: 01840001000001820 # this is not
good
from HEX2ASCII: #
gives me empty

data to so socket: 0010600503737333331ß # here is REAL part
(0010600 is belongs to header, but after that data). But because there
is no header any more we doun't reqocnice this any more and we think
its garbage
data to so socket:
data to so socket: 018300010000

data to so socket:
data to so socket:
data to so socket:
data to so socket:


--------------------- SNIP ------------------------------------------

So how can I take the real part for processing if it's cutted out from
the string ?

I know that data part which I'm interested starts wit 0x02 end with
code 0x03. So I think that I should do it like this:

listen socket and take one mark at time to process -- do it
until we get 0x02
descard everything else before 0x02
if 0x02 then
append every mark to $MyDatastring until 0x03
do something wirh the data and start from beginning


Any help would be nice

Thansk advance
-Jussi

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Socket() failed for UDP socket Kishore_R Perl Misc 2 10-11-2005 08:57 AM
Cisco 3620 VPN not listening UDP 500 / 4500 Jan Baggen Cisco 1 08-01-2005 10:46 PM
Interruptions in live news listening Realone Player listening Thaqalain Computer Support 6 07-16-2005 02:11 PM
Listening socket not seen outside of localhost Christian von Essen Python 2 06-21-2004 04:11 PM
udp (0) -> udp (0) traffic ? Tom Cisco 2 03-04-2004 06:06 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57