Link to home
Start Free TrialLog in
Avatar of jonasmit
jonasmit

asked on

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of jonasmit
jonasmit

ASKER

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.  
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What port are you trying to use?
5000
Try 5432, or some arbitrary #.
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.
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
Try

netstat -a
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.

something is listening on 5000
and something else on same box has connected
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.

right but how to find what process?
why do you need to know?
you'll probably need a 3rd party application to determine which apps are listening on what port.
right but how to find what process?
i used tcpview to find out that it is svchost.exe.  it seems to have many ports open.  what for anyone?
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.
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.
Not sure, your better off asking those sort of questions in the Windows forum.
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.
Thx :)