It seems like a duplicate question of how to kill a process already running on that port, but it is a different question. When I killed the process and restart it, it still gives me that error message, seems like Netbeans has a problem, and the error message got stuck and keeps appearing even when the port is not in use.
I've used the tool at : http://www.yougetsignal.com/tools/open-ports/ to check the port : 6600
Here is what it says :
My code looks like the following :
import java.io.*;
import java.util.*;
import com.sun.net.httpserver.*;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import Utility.*;
public class Http_Server
{
static int Port=6600,Thread_Count=50,Resume_Count=0; // 8080
InetSocketAddress addr;
HttpServer server;
static String App_Id="Resume_App";
static Resume_Loader Resume_loader;
static Get_Time Timer=new Get_Time();
static Vector<String> Current_Keywords_Vector=new Vector();
static boolean Debug_B=true;
public Http_Server(int Port)
{
if (Port>-1) this.Port=Port;
Srart_Server();
}
void Srart_Server()
{
try
{
Resume_loader=new Resume_Loader();
addr=new InetSocketAddress(Port);
server=HttpServer.create(addr,0); // Line : 34
server.createContext("/"+App_Id,new MyHandler(server));
server.setExecutor(Executors.newCachedThreadPool());
server.start();
Out("Server is listening on port : "+Port);
}
catch (Exception e)
{
Resume_App.Save_To_Log(e.toString()+"\n"+Tool_Lib_Simple.Get_Stack_Trace(e));
e.printStackTrace();
Out(e.toString());
}
}
private static void out(String message) { System.out.print(message); }
private static void Out(String message) { System.out.println(message); }
public static void main(String[] args) { Http_Server Demo=new Http_Server(-1); }
}
It was running fine yesterday, but this morning I changed :
InetSocketAddress addr; to static InetSocketAddress addr;
HttpServer server; to static HttpServer server;
When I ran it, I got the following error message :
Server is listening on port : 6600
java.net.BindException: Address already in use: bind
at sun.nio.ch.Net.bind0(Native Method)
at sun.nio.ch.Net.bind(Net.java:437)
at sun.nio.ch.Net.bind(Net.java:429)
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
at sun.net.httpserver.ServerImpl.<init>(ServerImpl.java:100)
at sun.net.httpserver.HttpServerImpl.<init>(HttpServerImpl.java:50)
at sun.net.httpserver.DefaultHttpServerProvider.createHttpServer(DefaultHttpServerProvider.java:35)
at com.sun.net.httpserver.HttpServer.create(HttpServer.java:130)
at Http_Server.Srart_Server(Http_Server.java:34)
at Http_Server.<init>(Http_Server.java:24)
at Http_Server.main(Http_Server.java:51)
Then I realize if they are static, they might keep them selves in memory and occupy the port, so I changed them back to non-static like the above code. But now when I run it, the error message keeps appearing, and in Netbeans there is a "notification" saying something like : "package-info.class is in wrong place, delete it or put it in the right sub directory ..." don't remember the exact wording. But when I open the url, the web page works fine as if there is no error message, and when I stop the server the page won't appear as it supposed to be.
So it seems like a Netbeans 8.0.2 malfunctioning, but I don't know how to make the error message not appear, or as it suggested how to delete "package-info.class" or put it into the correct sub dir, I can't even find where it is, how to fix it ?