开发者

Socket Programming in Perl

I am new to Socket Programming. Here is what I am trying to do:

I would like to transmit a Packet to another Server in the network over an UDP Connection.

Here is the short code snippet I wrote in Perl:

# create udp socket
$sock = IO::Socket::INET->new(
  Proto       => "udp",
  PeerPort    => '5001',
  PeerAddr    => defined $ip ? $ip : 开发者_运维技巧'10.42.43.2'
) or die "Socket could not be created: $!\n";

I would like to handle the exception when the host (10.42.43.2) is not reachable. Any ideas how it can be done ?

Thanks you so much


UDP is an unreliable protocol, which means it doesn't provide a means of finding out if delivery was successful or not.

One option is to switch to a reliable protocol like TCP.

Another is to handle delivery notifications yourself. Have the host send a reply on receipt of your packet. If no reply has been received within X seconds, an error occurred.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜