aspose file tools*
The moose likes Java in General and the fly likes problem in java.net.Bind Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "problem in java.net.Bind Exception" Watch "problem in java.net.Bind Exception" New topic
Author

problem in java.net.Bind Exception

Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
hi,

In my Networking programming, How to kill the process that using a port no.
Actually, I started my Server program which was using a port say 4000. Now once I again starts the server , It shows the


Since, the port no. is in use.
I want to programtically unbind the used port . So that once i restart the server file it will kill the running porcess using that port.

Thanks
Abhijit


Abhijit Das
SCJP 5.0 | SCWCD 1.5
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

I surely hope nothing like that exists. For some ports it may not be that drastic, but what if I write an application that tries to bind on port 80? Boom! No more webserver. Port 135? Boom! File sharing is gone.

Instead you should close your application nicely, so it will unbind the port itself.

And by the way, port 4000 is reserved for something called Terabase. See IANA port numbers.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
hi,

I want the application should able to stop the running port first if it is used and then start executing the program. That is, to avoid java.lang.BindException.


thanks
Abhijit
Taariq San
Ranch Hand

Joined: Nov 20, 2007
Posts: 192
Originally posted by Abhijit Das:
hi,

I want the application should able to stop the running port first if it is used and then start executing the program. That is, to avoid java.lang.BindException.


thanks
Abhijit


As he said, you won't need to if the application has shutdown and freed up the resources.
So ask first why it's still in use.
Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
hi,
I just simply track the given port is using if not, create the socket with the port.else kill the port and then create the socket with the given port.

Thanks
Abhijit
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

It's _still_ bad. If you track down say port 80 and then destroy that, then you are destroying the default web server's ability to be connected to! What you need to do is have a snippet of code that tries to connect to a port that is free, so in other words have a loop that connects to a port, checks if it gets a Bind exception, if it does then try another port.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
Hello Martijn,

I understood your logic. But, the same code will be used in different nodes in cluster of servers. So, I will assign a specific port in harcoded and all the server should able to create ServerSocket in that port only, it shuold not through any BindingException.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in java.net.Bind Exception