I’m currently working / almost finished building the beta version of my communication application. I’m running my server on EC2 instance but somehow the server application keeps get stuck at “Port already in use” exception” when I check the server status few days later. But it is working fine for first few days. This could be due to some mistake I have made when I was coding but I’m also doubting I haven’t set up something on my linux OS yet. Is this something that happens occasionally to everyone?
=================================================
I’m mainly using follow lines of code to accept users constantly inside a loop
while (blinker != null) {
try {
ServerSocket ss = new ServerSocket(PORT, 10);
Socket connection = ss.accept();
//other stuffs going on
ss.close(); //forgot to mention that i actually close it all the time after accepting a new user
}
}
===================================
In addition to that, I’m mainly using port 443 and 80
Move the creation of the ServerSocket outside the loop. At present you are trying to create a new one every time you accept a connection, so you are conflicting with yourself. You only need one for the lifetime of the program.