• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to implement Online Chat Application using simple jsp and servlets

 
Snehitha Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am new here and am hoping that you may be able to give me a few pointers.

I am writing a chat application in Java.

I have a client that connects to the server and sends over a username. The username is stored in the new thread instance. This way the server can distribute the chat name as well as the conversation text to all the clients

so everyone knows who is talking.

What approach should I take to achieve this?? What would be the most sensible way of doing it?

Till now what i did is i just create a Loginservlet,when the user login to the application using login.jsp page i store this username in a session and add this username into ArrayList object.
If somebody access this application from other system and logs in using another user name according myrequirement the list size is must be two.but still it is showing size as 1 only.

can somebody help me on this.how can i add all login users from different systems how can we add all the login usernames into this list object....

I am eagerly waiting for your reply.

Thanks in advance for your comments.

SNEHITHAPRASAD
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would need Ajax also. Only Servlets and JSP won't suffice to make it close to real time.
Then there are two possible approaches from my view, one is the chatroom where everyone sees what every other user sends. Other is the personal chat option like GTalk.
First one would require less effort as all messages are simply broadcasted.
 
Snehitha Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit Ghorpade,

Thanks for your quick response.

Actually i did the first approach.I mean i implemented the first approach like everyone sees what every other user sends without using Ajax ,In this i use servlets and jsp. But i want how to implement one-to-one chatting. Can you please give some inputs to implement one-to-one chatting.

Thanks in Advance.

SNEHITHAPRASAD
 
K. Tsang
Bartender
Posts: 3507
16
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mention storing the user login in a session variable. And sessions are user specific, every login has its own session. I may consider storing the user login in an application or context variable instead.

Yet another approach is to have a POJO as your so-called logged-in collection. As people log in you add his username to your POJO.

Thinking about it either approach makes this collection thing application level.
 
Snehitha Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi K.Tsang ,

Thanks for your replay.Can you please give me some inputs on how to implement one-to-one chating using servlets and jsp.

Thanks in advance,

SNEHITHAPRASAD
 
Bhoopendra Singh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since session is specific to single user, storing signed in user details in session will not work. You need to store signed in users details in location which accessible from all live session. One of the option is application context. Other maybe some some external persistent storage.
Also, since this is a web based application, which approach is being used "Pull" or "Push" to show incoming chat message?
 
Juran Novarski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

I'm also having a project a chat application with java.. I'm jus wondering that how to set up the connection between the client and the server? Does it have to set up lan connection?

can someone explain the processes invlove in this applicaton?

Thank you!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSPs probably don't figure much into it. It'd be HTML pages that use some JavaScript library (like jQuery) to pass JSON back and forth to the server.
 
Juran Novarski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm..what i'm trying to say is that how can this be implemented through java? what are the processes?
 
Juran Novarski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can the this application done by assigning a pc as the server and others as the client??
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You probably would use servlets on the server-side, and jQuery in the browser. If you aren't familiar with these technologies, start reading up on them.
 
Juran Novarski
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick reply

Me,and my team would like to make a desktop application of that. For he fact that we are still newbies, sutdents, i would just like to ask your kind knowledge on how can we set up the application by implementing as desktop application of chat. Do we have to set up the lan connection by testing our program?? How should we tes the server side? How about he client side? What are the necesary technologies to be used?
Sorry if I asked too much about this because I really don't know how to continue making without knowing what to do next.

Thank you
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I said, servlets on the server-side in a container such as Tomcat. Doesn't matter whether the client is a browser or a standalone app.

A Java desktop client would likely use a library like Apache Commons HttpClient (or maybe even just the java.net classes that deal with HTTP) to access the server.

It doesn't matter whether the clients and the server run on different machines, or for testing purposes all on the same machine - the clients just need to know the IP address and the port on which to connect to the server.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic