using java networking - problem with Address already in use.

I am using the networking api in java to run a simple chat application.  I have modified some code from the deitel book (DeitelMessenger ch 17 vol. 4 of how to program book) but i don't think it is necessary to see that code to understand the problem.
I started the server.  tested it with the clients and everything seemed to be working correctly.  perhaps i stopped the server incorrectly and now when i try to restart it i get the following message:

java.net.BindException: Address already in use: JVM_Bind
        at java.net.PlainSocketImpl.socketBind(Native Method)
        at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:331)
        at java.net.ServerSocket.bind(ServerSocket.java:309)
        at java.net.ServerSocket.<init>(ServerSocket.java:183)
        at java.net.ServerSocket.<init>(ServerSocket.java:139)
        at edu.uncc.messenger.sockets.server.SecureMessengerServer.startServer(S
ecureMessengerServer.java:25)
        at edu.uncc.messenger.sockets.server.SecureMessengerServer.main(SecureMe
ssengerServer.java:71)>

I fortunately have another computer and have used it as the server and been able to start it and stop it multiple times and point at it with my laptop on my lan.  however, i would like to be able to fix it so i can do it all on my laptop.  also, i used my pc where the server works and when i tried to start it twice i got the same error above leading me to believe it is still running somehow.  but how do i find what piece of code to kill?  it isn't in my processes list (using winxp) and i don't know how else to find out if this thing is still running.
any suggestions?
LVL 1
jonasmitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
I think you're probably right and it's throwing this error as it's already running. Start the applications from the command line and stop them with Ctrl-C.
0
jonasmitAuthor Commented:
unfortunately that error is thrown when i try to restart the server.  so i try to run it but i can't.  so how do i kill it with CTRL-C?  know what i mean?  Rebooting doesn't help.  
0
objectsCommented:
> Rebooting doesn't help.  

If you still get the problem after rebooting your PC, then some other application is already using the port you are attempting to listen on.
Try changing the port number used by your application.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

AlephCommented:
What port are you trying to use?
0
jonasmitAuthor Commented:
5000
0
objectsCommented:
Try 5432, or some arbitrary #.
0
jonasmitAuthor Commented:
i changed the port to 5001 and everything is alright.  but of course i don't want port 5000 open forever.  anybody know how i can kill this app that is somehow running in the background?  i don't see it in the processes list unless it is masked somehow.
0
objectsCommented:
As you stated above that you got the same error after you rebooted your PC then it must be some other application (not yours) that has it open.

Unless you are trying to open two ServerSockets on the same port in your application.

Try rebooting your PC and *before* starting your application attempt to telnet to port 5000 todetermine if it is open:

telnet 127.0.0.1 5000
0
CEHJCommented:
Try

netstat -a
0
jonasmitAuthor Commented:
thanks for all the help...

netstat -a produces a list something like this:
Proto   Local Address    Foreign Address    State
TCP     [mycomp]:5000       [mycomp]:0      LISTENING
TCP     [mycomp]:2050       localhost:5000  TIME_WAIT
where I insterted [mycomp] for my computer's name on the network
I realize we are getting away from my orig. question but...
how can i find what app has this port open (or any port for that matter)?  And can anyone tell me exactly what is going on based on this new info.  As in localhost vs. [mycomp] and the local address vs. foreign address.
thanks for all your help.

0
objectsCommented:
something is listening on 5000
and something else on same box has connected
0
jonasmitAuthor Commented:
thanks for all the help...

netstat -a produces a list something like this:
Proto   Local Address    Foreign Address    State
TCP     [mycomp]:5000       [mycomp]:0      LISTENING
TCP     [mycomp]:2050       localhost:5000  TIME_WAIT
where I insterted [mycomp] for my computer's name on the network
I realize we are getting away from my orig. question but...
how can i find what app has this port open (or any port for that matter)?  And can anyone tell me exactly what is going on based on this new info.  As in localhost vs. [mycomp] and the local address vs. foreign address.
thanks for all your help.

0
jonasmitAuthor Commented:
right but how to find what process?
0
objectsCommented:
why do you need to know?
0
objectsCommented:
you'll probably need a 3rd party application to determine which apps are listening on what port.
0
jonasmitAuthor Commented:
right but how to find what process?
0
jonasmitAuthor Commented:
i used tcpview to find out that it is svchost.exe.  it seems to have many ports open.  what for anyone?
0
jonasmitAuthor Commented:
sorry so many questions. I am learning at least.
I used win xp's TASKLIST /SVC ang the svchost that matches the pid says LmHosts, RemoteRegistry, SSDPSRV, WebClient
Is this a normal system process?  
I don't like ports open i don't know about.
0
jonasmitAuthor Commented:
sorry so many questions. I am learning at least.
I used win xp's TASKLIST /SVC ang the svchost that matches the pid says LmHosts, RemoteRegistry, SSDPSRV, WebClient
Is this a normal system process?  
I don't like ports open i don't know about.
0
objectsCommented:
Not sure, your better off asking those sort of questions in the Windows forum.
0
jonasmitAuthor Commented:
yeah good point I have somewhere to go though.  finally figured out what is happening at least.  I looked up a few things and it seems to be a normal process so i am not too worried anymore.  ok well i'll close this out. wish i could distribute the points.
0
objectsCommented:
0
objectsCommented:
Thx :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.