• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem in java.net.Bind Exception

 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic