2

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

1 Answer 1

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I tried the second approach since changing from tcp to udp would require a lot of design changes. Thanks for your time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.