Any suggestions on how to wait for a packet of unknown length on the socket, and do some processing with payload bytes as efficiently as possible?

I need to write a UDP server that will wait for packets from uncorrelated devices (maximum 10,000 of them) that periodically send small packets; do some processing using the payload and write the results in SQL. Now I'm done with the SQL part via jdbc, but the payload bytes continue to listen on me, how should I access them? So far, I have worked with a payload mapped to a string, and then converted the string to hexadecimal (two hexadecimal characters representing one byte). I know there is a better way to do this, but I don't know that ...

+4
source share
1 answer

Would you like to create a DatagramSocket and get a DatagramPacket on it?

You need to specify the maximum packet length using the buffer you use to create it, but then you can find out how much data was actually sent in the packet using getLength() .

See the Java Tutorial for more details.

+2
source

Source: https://habr.com/ru/post/1396367/


All Articles