So I made a simple UDP client and server using IO::Socket. The code is given below. The problem is that the server prints the message from client only when it ends with a newline. Is there a way to change this? I tried disabling output buffering on the client side, but that didn't work.
client.pl
use IO::Socket;
use strict;
use warnings;
my $sock = IO::Socket::INET->new(
Proto => 'udp',
PeerPort => 23456,
PeerAddr => '10.254.83.40',
) or die "Could not create socket: $!\n";
select($sock); $|=1;
$sock->send("message from client") or die "Send error: $!\n";
server.pl
use IO::Socket;
use strict;
use warnings;
my $server = IO::Socket::INET->new(LocalPort => 23456,
Proto => 'udp')
or die "Couldn't be a udp server on port 23456
+: $@\n";
my $MAX_TO_READ = 1024;
my $datagram = '';
while($server->recv($datagram, $MAX_TO_READ)){
print $datagram;
}