UDP receive

A

aku

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
 
U

Uri Guttman

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
 
A

aku

  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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top