File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes Java Chat Server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "Java Chat Server" Watch "Java Chat Server" New topic
Author

Java Chat Server

Nathan Popham
Greenhorn

Joined: Sep 23, 2009
Posts: 9
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?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
What protocol does your "chat server" use to talk to clients?

If HTTP then a servlet container is an obvious choice.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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?
Nathan Popham
Greenhorn

Joined: Sep 23, 2009
Posts: 9
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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

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.
Jonas Isberg
Ranch Hand

Joined: Mar 18, 2003
Posts: 118
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.
Nathan Popham
Greenhorn

Joined: Sep 23, 2009
Posts: 9
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?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
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.

HTH


love your job and not your company;
...because you never know when your company will stop loving you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Chat Server