I'm trying to create a chat server on Java that will store some messages and send them to requesting clients. The way I have it now, the server runs continuously, only becoming active when a client connects and asks for content (it's up to the client to ask, the server only responds. The messages are kept in memory in a Java array.)
Now I'm trying to figure out how to run the Java server on an actual Linux server. Are servlets what I should look into? Is there another way that I can have my Java server running continuously on the server so that I don't have to change the program?
It sounds like you already have a server written. In which case I don't think you want to rewrite it just because it's going to be run on a different computer. Did you have a problem when you tried to run it on your Linux server? Or have you just not tried it yet?
Joined: Sep 23, 2009
William, I'm using sockets. I don't know what protocol those use.
Paul, I can put the file on the server, but I don't know how to have the server run it. I would of course be extremely happy to use the server as-is without having to modify it. Most of the information I have found online about Java servers are about servlets, which is why I thought I might need to make my server into a servlet.
Nathan Popham wrote:Paul, I can put the file on the server, but I don't know how to have the server run it.
Now I'm confused. You keep saying things which imply you've written a server program. Is that true or is it not? If you have written a server program then you can run it on any machine which has a Java VM installed. And the way you would run it there is the same as the way you would run it on your machine.
Nathan Popham wrote:I can put the file on the server, but I don't know how to have the server run it.
Are you using a web hotel and uploading the file via ftp or some web interface? If you are and if you have ssh
access to your account you can try and start it that way. You might not be allowed to start a server according
to some web hotel rule though.
Joined: Sep 23, 2009
Jonas Isberg wrote:
Are you using a web hotel and uploading the file via ftp or some web interface?
This is what I have. I have ssh and ftp access to the server, which is running Apache, I believe. I've tried with ssh, but it returns a permission error, and I don't see how anything I start with ssh will continue for longer than the ssh is open, anyway. Can I use some sort of software, or do I need to get physical access to the server to run it continuously?
Nathan Popham wrote:
I've tried with ssh, but it returns a permission error, and I don't see how anything I start with ssh will continue for longer than the ssh is open, anyway. Can I use some sort of software, or do I need to get physical access to the server to run it continuously?
Servlets are for building web applications.
As Paul said, if you've got a standalone Java application working then you probably don't need to write servlets.
What you do need, is a quick tutorial on Unix.
Specifically, you'll want to look up chmod which is the command for changing file permissions.
You should also look up nohup (No Hangup) which will allow you to start a process that will keep running after you log off.
I'm going to move this to our Unix forum where you can get more help with these commands.
As was mentioned earlier, if you're renting space on someone else's server, you probably won't be granted permission to bind to your own ports to run your chat server.
You'll have to check with whomever you're renting from.
I guess you are running the server from ssh prompt and after you come out of that console, your server is no more running. If this is the case, you can fix it in one of the following ways-
1. start the server in background by adding " &" at the end of your command and exiting the terminal window.
2. Creating nohup for this command. I have used it long back and I don't remember the steps but you can google it.
love your job and not your company;
...because you never know when your company will stop loving you!