• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Chat Server

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What protocol does your "chat server" use to talk to clients?

If HTTP then a servlet container is an obvious choice.

Bill
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic