wood burning stoves 2.0*
The moose likes Sockets and Internet Protocols and the fly likes DatagramSocket of open JDk is not throwing Socket Exception even if port is bound Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "DatagramSocket of open JDk is not throwing Socket Exception even if port is bound " Watch "DatagramSocket of open JDk is not throwing Socket Exception even if port is bound " New topic
Author

DatagramSocket of open JDk is not throwing Socket Exception even if port is bound

Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
Hi,

I am using Open JDK and observed that DatagramSocket is not throwing socket exception even though 162 port which i am passing to DatagramSocket constructor is already bound by other exception. But same is working in java 6

Thanks,
Nisha
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10059
    
163

Which version of Open JDK are you using and where did you get it from? What does the code look like and on what line of the code do you expect an exception?

[My Blog] [JavaRanch Journal]
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
We are using Open JDK 7 release number is 146
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7676
    
  19

Nisha lakshminaraya wrote:can you please help me?

Nisha, you need to EaseUp (←click).

Jaikiran asked if you could post some code (just the relevant bits please; we DON'T want to see your entire app), but you haven't bothered to provide this. We therefore have no idea what you're trying to do, so it would be useless to provide advice.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
code that i am trying to access is

DatagramSocket dSocket = new DatagramSocket(162);

with jave 6 this was throwing an socket exception but with Open jDK its not throwing any exception.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7676
    
  19

Nisha lakshminaraya wrote:with jave 6 this was throwing an socket exception but with Open jDK its not throwing any exception.

Then, with the information you've given us, the answer is: I don't know. The only thing I can confirm is that it is documented to throw SocketException; but why it doesn't in your case I have no idea, because you haven't provided enough information.

One line of code doesn't tell us anything. We could have worked that out for ourselves. I suggest you look at the SSCCE page.

Winston
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
It was working in java 6 but with open JDK 7 . its not working. any idea how to resolve this?
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
Let me know other details your looking for because when i debugged the line which i have sent that's

DatagramSocket ds = new DatagramSocket(162)

is not throwing any exception. Is there any alternative for this?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10059
    
163

This is the javadoc of that constructor:

Constructs a datagram socket and binds it to the specified port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel.


So the kernel will chose the IP address to bind to. Unless some other socket is already bound to that same IP and port combination, it won't fail to bind. How are you checking that some other socket is bound to the IP + port combination?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7676
    
  19

Nisha lakshminaraya wrote:It was working in java 6 but with open JDK 7 . its not working. any idea how to resolve this?

Nisha, that is simply a duplication of what you've already said. And since you don't seem to be interested in offering anything more than 1 line of code - the answer is: No.

Winston
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
I am using SNMP to communicate with the device, where i want listen for traps on the port 162. If this port is bound i want to add next port thats 163.

So here i am using DatagramSocket to get ports. Here i am only passing port.

I am running net snmp to block 162 port.

last year when i was doing above i was getting an socet exception but once i moved to Open JDK 7, i am getting any error.

If i run netstat -nao, i could see two process's are listening to 162 port and both applications are not receiving any traps.

code is below:

dSocket = new DatagramSocket(trapReceivePort);



receiveThread = new Thread(this);

errorLog = errorReceiver;
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
I am trying to bind to local IP address it self
Nisha lakshminaraya
Ranch Hand

Joined: Feb 23, 2010
Posts: 30
Jaikiran Pai wrote:This is the javadoc of that constructor:

Constructs a datagram socket and binds it to the specified port on the local host machine. The socket will be bound to the wildcard address, an IP address chosen by the kernel.


So the kernel will chose the IP address to bind to. Unless some other socket is already bound to that same IP and port combination, it won't fail to bind. How are you checking that some other socket is bound to the IP + port combination?


I am trying to bind to local host that's 127.0.0.1.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10059
    
163

Nisha lakshminaraya wrote:

I am trying to bind to local host that's 127.0.0.1.


Then you are using the wrong constructor. If you want it to bind to a specific IP + port combination, then use one of the other available constructors. The one you are using will leave the IP selection to the kernel as already noted in its javadoc.
 
 
subject: DatagramSocket of open JDk is not throwing Socket Exception even if port is bound