?
Solved

using java networking - problem with Address already in use.

Posted on 2003-03-21
24
Medium Priority
?
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month13 days, 4 hours left to enroll

777 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