Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Sockets and Internet Protocols and the fly likes java udp socket programming problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "java udp socket programming problem" Watch "java udp socket programming problem" New topic

java udp socket programming problem

sam barker
Ranch Hand

Joined: Apr 26, 2008
Posts: 37
Hi All,
I am trying to create a udp socket.
It works fine but the program hhangs for a few seconds[at DatagramSocket clientSocket = new DatagramSocket();] before ti actually sends the data out.Could any one tell me why?


System.out.println("Creating datagram");
DatagramSocket clientSocket = new DatagramSocket();

InetAddress IPAddress =
byte[] sendData;
byte[] receiveData = new byte[1024];
String sentence ="TEST";
sendData = sentence.getBytes();
DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length,
IPAddress, 9876);

Vinay Naga

Joined: May 16, 2008
Posts: 6
I am new to this , I just tried the same program. Is it because , the DatagramSocket tries to send packets through the firewall and does it take some time to send thru it ?
sam barker
Ranch Hand

Joined: Apr 26, 2008
Posts: 37
Hi there,
Well I tried the code on a debian machine .It works fine.I had initially tried on a Ubuntu machine.
I agree. Here's the link:
subject: java udp socket programming problem