Prev: Please excuse the NOOB question - go easy on me please~!
Next: FAQ 4.76 How do I verify a credit card checksum?
From: aku on 26 Feb 2010 00:17 Hi, got a UDP msg with format STXdataETX (without a LF) I use this: use IO::Socket; my $PORT='4444'; $sock = IO::Socket::INET -> new(LocalPort => $PORT, Proto => 'udp') or die "socket: $@"; print "Server Mode\n"; while ($sock->recv($nachricht,1024)) { print "$nachricht"; }; with my incoming format STXdataETX (without a LF) it do not work; if I add a LF it works is there a chance to change the delimiter in the recv function from LF to ETX or are there other solutions for my program? Thanks a lot aku
From: Uri Guttman on 26 Feb 2010 01:07 >>>>> "a" == aku <aku(a)bluewin.ch> writes: a> Hi, got a UDP msg with format STXdataETX (without a LF) a> I use this: a> use IO::Socket; a> my $PORT='4444'; a> $sock = IO::Socket::INET -> new(LocalPort => $PORT, Proto => 'udp') or a> die "socket: $@"; a> print "Server Mode\n"; a> while ($sock->recv($nachricht,1024)) a> { a> print "$nachricht"; a> }; a> with my incoming format STXdataETX (without a LF) it do not work; if I a> add a LF it works a> is there a chance to change the delimiter in the recv function from LF a> to ETX or are there other solutions for my program? udp does not have a delimiter and you don't need one if your message is always under a packet size. i would bet the issue is on the client side as needing a lf implies it is line buffered and isn't being flushed until a lf (newline) is sent. are you using print to send the packet? try using send() on a udp client socket and it should work. uri -- Uri Guttman ------ uri(a)stemsystems.com -------- http://www.sysarch.com -- ----- Perl Code Review , Architecture, Development, Training, Support ------ --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
From: aku on 27 Feb 2010 14:48
On Feb 26, 7:07 am, "Uri Guttman" <u...(a)StemSystems.com> wrote: > >>>>> "a" == aku <a...(a)bluewin.ch> writes: > > a> Hi, got a UDP msg with format STXdataETX (without a LF) > a> I use this: > > a> use IO::Socket; > a> my $PORT='4444'; > a> $sock = IO::Socket::INET -> new(LocalPort => $PORT, Proto => 'udp') or > a> die "socket: $@"; > a> print "Server Mode\n"; > a> while ($sock->recv($nachricht,1024)) > a> { > a> print "$nachricht"; > a> }; > > a> with my incoming format STXdataETX (without a LF) it do not work; if I > a> add a LF it works > a> is there a chance to change the delimiter in the recv function from LF > a> to ETX or are there other solutions for my program? > > udp does not have a delimiter and you don't need one if your message is > always under a packet size. i would bet the issue is on the client side > as needing a lf implies it is line buffered and isn't being flushed > until a lf (newline) is sent. are you using print to send the packet? > try using send() on a udp client socket and it should work. > > uri > > -- > Uri Guttman ------ u...(a)stemsystems.com -------- http://www.sysarch.com-- > ----- Perl Code Review , Architecture, Development, Training, Support ------ > --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com--------- Hi, no, I use the send(). I tried all the things I can imagin. No success *) - at least I wrote the prog again locking exact as the oldone (ascii). Then it works fine. Think there whos a kind of a whitspace somewhere in the $msg *) one thing which whose running was the >>print "$nachricht$/";<< which tell me that there is a not expected delimiter Ok, here the newritten running prg; use strict; use IO::Socket; my $serverIP = '192.168.1.35'; my $serverPORT='4444'; my $sock = IO::Socket::INET -> new(Proto => 'udp') or die "socket: $@"; my $ipaddr = inet_aton($serverIP); my $portaddr = sockaddr_in($serverPORT,$ipaddr); my ($msg,$tre); while (1) { crea_msg(); print "$msg\n"; my $lmsg = length($msg); send($sock,$msg,0,$portaddr) == $lmsg or die "send problem\n"; sleep (3); }; exit; sub crea_msg { my @t = localtime(time); if ($tre > 400){$tre = -100} else {$tre = $tre + 7}; $msg = sprintf("\x02%04d.%02d.%02d,%02d:%02d,%d\x03", $t[5]+1900,$t[4]+1,$t[3],$t[2],$t[1],$tre); return; }; thanks again Turi |