473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

java.net.BindException: Address already in use: JVM_Bind

Hi, i am using NetBeans IDE 6.0.1 and i created a server project and a client project, first i run the server that listens to the port "8221" and waits for clients accessing that port, and when i run the client that accesses the server at port "8221" the IDE throws this exception
"Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)"

By the way, i checked for any process using the same port in the command window by typing "netstat -a" and i didn't find any.

The server code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.             ServerSocket server = new ServerSocket(8221);
  3.             System.out.println("Waiting for clients\n");
  4.             Socket connection = server.accept();
  5.             ObjectInputStream input = new ObjectInputStream(connection.getInputStream());
  6.             ObjectOutputStream output = new ObjectOutputStream(connection.getOutputStream());
  7.             StringBuffer buff = new StringBuffer();
  8.             do {
  9.                 int c = 0;
  10.                 while (((c = input.read()) != '\n') || ((c = input.read()) != -1)) {
  11.                     buff.append(c);                    
  12.                 }
  13.                 msg = buff.toString();
  14.             } while (msg != "Exit");
  15.             System.out.println(msg);
  16.         } catch (IOException ex) {
  17.             Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  18.         }
  19.  
The client code:
Expand|Select|Wrap|Line Numbers
  1. try {
  2.  
  3.             Socket client = new Socket(InetAddress.getLocalHost(),8221);
  4.             //Socket client = new Socket("192.168.1.18",8221);
  5.             ObjectInputStream input = new ObjectInputStream(client.getInputStream());
  6.             ObjectOutputStream output = new ObjectOutputStream(client.getOutputStream());
  7.             String msg = "Hello Exit";
  8.             output.writeBytes(msg);
  9. //            StringBuffer buff = new StringBuffer();
  10. //            do {
  11. //                int c = 0;
  12. //                while (((c = input.read()) != '\n') || ((c = input.read()) != -1)) {
  13. //                    buff.append(c);
  14. //                }
  15. //                msg = buff.toString();
  16. //            } while (msg != "Exit");
  17.         } catch (IOException ex) {
  18. //            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  19.             System.out.println(ex);
  20.         }
  21.  
Thanks.
Nov 6 '08 #1
1 23909
itsraghz
127 100+
That's because the Java program/process is still running. Did you abruptly shutdown your Netbeans IDE?

Try closing Netbeans and run the program again. It should work fine!
Nov 6 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: BB | last post by:
In several of my JSP pages I get this error:- java.net.BindException: Address Already in use:connect I cant think why, I close off my database connections when finished, the code I use to...
3
by: Magnus Lycka | last post by:
I have a socket server like below which I want to exit when it's out of data. If I interrupt the client, I'll get a broken pipe on the server side, and after a Ctrl-C, I can restart the server...
2
by: Aleksander Wodynski | last post by:
I have server, daemon and client (daemon and client on the same machine). When client starts it send query to the server, server send query to the deamon (daemon check if the client exist), daemon...
0
by: Eric.Hillmuth | last post by:
I'm just getting started with postgresql and things are going pretty well. However, I seem to be having trouble connecting to my database via TCP/IP. I'm assuming that my problems are related to...
11
by: Tor Erik | last post by:
Hi, The reason is that my application does about 16 connects and data transfers per second, to the same 16 remote hosts. After approx 200 secs there are 4000 sockets waiting to be garbage...
0
by: sivasankarmathuraju | last post by:
Hi! I am using: Java 2 SDK 1.4.0 Standard Edition on Windows XP I have one java client application and one gateway that is in C language runing on the same machine. The server creates a...
1
by: wesomon99 | last post by:
Hello, I have a JBoss web application (v4.04GA), run on an Apache Tomcat HTTP server (v5.5.17). It connects with a MySQL database (v4.1.10). My web application takes an XML file, creates a CSV file...
4
by: santosh.tripathy | last post by:
We have a requirement where in a java based web application is getting integrated with the existing .net based web pages. The .net based web pages are secured through forms authentication. Is there...
1
by: ntech | last post by:
hello, i got a problem while restarting postgresql, i removed postmaste.pid and even the temporary sock file and while restarting postgres, i got the following error: LOG: could not bind IPv6...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.