1 Reply Latest reply on Feb 16, 2011 7:30 AM by jpiel

    Reading UDP packets in J2EE environment

    piotrekde

      Hi guys,

       

      In my application based on JBoss (version 5) I need to listen for UDP packets. The easies way (and probably the only one ) is to open DatagramSocket on certain port (using JBoss @Service singleton bean) and call receive(...) method. The first part is pretty easy - I've tested it and works as expected. Second part - receiving packets is more complicated. I am wondering about design of such a code. As it is stated in DatagramSocket javadoc, receive is a blocking operation - it blocks until packet is retrieved. How to code it to make sure that it is fast, scalable and thread-safe?

      I thought about writing stateless beans that holds a reference to singleton with opened connection, and those beans are calling receive method - but I am not very sure how JBoss would manage those beans. Is there any pattern to use?

       

      Thanks in advance,

      Piotr