Dear Monks,

I'm new to networking and threading in Perl, and I got the following task which I can't solve.

We have a server which listens on 4 ports. And once it receives a "heartbeat" (a byte containing "01") it sends a response to the IP and port the hb came from (byte containing "25"). This sets up the connection. We have to repeat this in every 10 seconds to keep it alive. After the the server got the first hb it starts to send hexdumps to the client which we have to log into files.

If everything went fine we should have 4 threads signaling the server. 4 other threads listening to the responses and logging the hexdumps.

The problem is that I can't manage to simultaneously listen to the same port and send on it. I have to use UDP and can't afford to miss anything the server sends. Also the code of the server can't be changed.

Update:

I got it to work. Thank you for all the replies. Now, as a finishing touch I have to log the result of the recv to a file as the following pattern:

0A 16 68 00 96 44 01 08 08 05 12 20 3B 00 00 00

Do you have a good idea how can I do the conversion?


In reply to UDP connection by falstad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.