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....
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.
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.
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.
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?
hmm..what i'm trying to say is that how can this be implemented through java? what are the processes?
Joined: Jan 03, 2013
How can the this application done by assigning a pc as the server and others as the client??
Joined: Mar 22, 2005
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.
Joined: Jan 03, 2013
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.
Joined: Mar 22, 2005
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.
subject: How to implement Online Chat Application using simple jsp and servlets