Address already in use..
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, June 27, 2001 09:10 AM

I have a program that listens for information over the network, using DatagramSocket's,and DatagramPacket's I have it running from a thread, so i can start and stop it at will, The problem is when i start the thread it starts listening for information, I then stop it, and it stops fine, but when i go to start it again, it tells me that it cant bind the socket and the address is already in use I know this is because i did not close the socket for obvious reasons ( if i did then it would only hear the first piece of info then stop, is there any way around this ? Thanks, Michael    More>>

I have a program that listens for information over the network, using DatagramSocket's,and DatagramPacket's


I have it running from a thread, so i can start and stop it at will,


The problem is when i start the thread it starts listening for information,


I then stop it, and it stops fine,

but when i go to start it again, it tells me that it cant bind the socket and the address is already in use


I know this is because i did not close the socket for obvious reasons ( if i did then it would only hear the first piece of info then stop,

is there any way around this ?


Thanks,


Michael

   <<Less

Re: Address already in use..

Posted By:   Carlos_Guardiola  
Posted On:   Tuesday, July 3, 2001 07:46 AM

Hi,

Try using a ServerSocket and a ThreadPool instead. The ServerSocket listens in a port, and when it detects any incoming conection, it selects a thread from the pool and the thread itself opens and closes the socket.

That way, you have a port in use by the ServerSocket (wich you donĀ“t need to stop or start) and a thread pool (wich you can stop and start)

Have a look at chapter 13 in http://developer.java.sun.com/developer/Books/threads/
it should help you.

Bye,

Carlos

About | Sitemap | Contact