Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

using java networking - problem with Address already in use.

Posted on 2003-03-21
24
Medium Priority
?
367 Views
Last Modified: 2007-12-19
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?
0
Comment
Question by:jonasmit
  • 11
  • 10
  • 2
  • +1
24 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 8183442
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
 
LVL 1

Author Comment

by:jonasmit
ID: 8183526
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
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 8184458
> 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Expert Comment

by:Aleph
ID: 8184507
What port are you trying to use?
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8184521
5000
0
 
LVL 92

Expert Comment

by:objects
ID: 8184528
Try 5432, or some arbitrary #.
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8184541
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
 
LVL 92

Expert Comment

by:objects
ID: 8184554
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 8184686
Try

netstat -a
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8184730
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
 
LVL 92

Expert Comment

by:objects
ID: 8184756
something is listening on 5000
and something else on same box has connected
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8184760
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
 
LVL 1

Author Comment

by:jonasmit
ID: 8184937
right but how to find what process?
0
 
LVL 92

Expert Comment

by:objects
ID: 8184952
why do you need to know?
0
 
LVL 92

Expert Comment

by:objects
ID: 8184957
you'll probably need a 3rd party application to determine which apps are listening on what port.
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8185015
right but how to find what process?
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8185019
i used tcpview to find out that it is svchost.exe.  it seems to have many ports open.  what for anyone?
0
 
LVL 92

Expert Comment

by:objects
ID: 8185044
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8185067
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
 
LVL 1

Author Comment

by:jonasmit
ID: 8185080
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
 
LVL 92

Expert Comment

by:objects
ID: 8185081
Not sure, your better off asking those sort of questions in the Windows forum.
0
 
LVL 1

Author Comment

by:jonasmit
ID: 8185087
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
 
LVL 92

Expert Comment

by:objects
ID: 8185089
0
 
LVL 92

Expert Comment

by:objects
ID: 8185093
Thx :)
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question