I am trying to write a chat program for my web page. I am not sure on a few things. I have the program running perfectly on my home computer. There is a server object that handles incomming connections by using ServerSockets and then calling its accept() method. When a connection comes in it creates a seperate thread to handle each individual connection. On the client side I just create a socket connection to the server that is already running. I use my computer name and the port as arguments. The client sends a message to be posted to the server. The server maintains a list of all the open connections and handles dead connections as well. The server receives a message to display and sends it to all the clients.
Here are the questions. I think I need to have the server side running on my web server (lunarpages hosting using resin 2.1.* servlet runner). I think I need to use servlets to do this. Or can you run a java program on the server side without servlets? I know that servlets are mostly used to create dynamic HTTP content like PHP but I am getting the impression that you can run pretty much any other java code through them. Is this correct? The problem is that with my current model the server program needs to continuously monitor a port for incoming connections. This means first of all that I need to find a free port on the server and monopolize it. It also means that the client needs a way of finding out which port to connect to. I can figure the port stuff out myself but what I am woried about is; do host providers allow users to keep a java program continuously running? Keep in mind that the program will be blocking on the ServerSocket.accept() fuction and for the most part will be using 0 cpu cycles. Also, as it is a small chat there will only be a few other threads running (one for each chatter). The program will also use up one of the servers ports while it is executing and waiting for connections on that port(I know I know there are like 65000 of them but I don't know). I don't think that my host will allow this, or will they?