Hello friends, its been long time since I wrote something on this blog site. For some time I off tracked myself from core GIS. Was busy in doing some real time messaging framework design. Did something cool on udp based reliable messaging and gis information exchange. The technology that I developed is all about sharing realtime data across enterprise through radio network. Later found somebody in the market doing similar thing. Have a look on Realtime Innovations. It does quite good stuff.
Mostly distributed caching/load balancing happens based on TCP at the lower level. But the same thing can be done using UDP. UDP by itself unreliable which means packet that is sent for delivery may or may not reach the destination. There may be chances of duplicate packets across nodes while on radio network. There may not be any packet sequencing while reaching the destination. All these are headache of using UDP. Still, people uses UDP for better bandwidth use and its multicast/broadcast facility.
I want to share some quick tips to other developers who are new to java socket programming to make their life easier while doing udp socket communication:
Mostly distributed caching/load balancing happens based on TCP at the lower level. But the same thing can be done using UDP. UDP by itself unreliable which means packet that is sent for delivery may or may not reach the destination. There may be chances of duplicate packets across nodes while on radio network. There may not be any packet sequencing while reaching the destination. All these are headache of using UDP. Still, people uses UDP for better bandwidth use and its multicast/broadcast facility.
I want to share some quick tips to other developers who are new to java socket programming to make their life easier while doing udp socket communication:
- DO usual socket creation steps like creating DatagramSocket/MulticastSocket based on your requirement
- Make sure you have set reusable address property on the socket object. It helps you you bind another socket on the same port
- Join a multicast group if you want to receive multicast packets
- MOST important set socket send/receive buffer size properly set. By default it is 8KB for a linux machine. Set some big value (i.e. 2MB) based on the traffic on the receiving port
- Prepare each packet below MTU level(i.e 1024 bytes). Generally network MTU(maximum transmission unit) is 1500 bytes. By making packet size below MTU, you overcome the risk of network packet fragmentation during transmission.
- Close your socket after job is done
- Leave multicast group