• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We are using Open JDK 7 release number is 146
 
Winston Gutkowski
Bartender
Pie
Posts: 10430
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10430
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was working in java 6 but with open JDK 7 . its not working. any idea how to resolve this?
 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10430
63
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to bind to local IP address it self
 
Nisha lakshminaraya
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic