JSP Chat Application

Hello...
I have done chat application in core Java. Now i want to build web-based chat & I want to use JSP for that. Can any one tell me the proper way to do this ?
I'm able to send message from JSP to Server, but how can i send message from Server to JSP ?
Please Guide me...
Thanks
//PremInd

Hi sagar,
Try this
http://www.web-tech-india.com/software/jsp_chat.php
http://www.hotscripts.com/Detailed/54273.html

Similar Messages

  • Null pointer exception in jsp ,data missing in chat application

    Hi all....
    I have a chat application in jsp using ajax.I have opened a d/b connection in a jsp which is called each time I sent a message.But sometimes I get null pointer exception in this page when msgs are sent so fast...also I miss some of the msgs I sent....I can't avoid that connection ther..When I commented all those d/b connection statements...everything is working fine..Please suggest me any solution...
    Thanks in advance.

    Hi,
    Am not getting exception now.In the jsp wer I ve written connection,am taking some values using request.getParameter("msg") . I had opened the connection statement before getting these parameter values.Think I ws getting null pointer exception due to this.Now I have opened connection after getting these parameter values...anyway am not getting the exception now...
    Thanks.

  • Need help regarding develpment of  a chat application in java

    hi
    well, i would like to know what is the best and simple technolgy to develop a simple chat application. I was searching this on internet and found some using servlets and JSP's, applets, RMI etc. I dont know exactly which to use. Infact iam new to java and if someone can help me out with this, i can start reading the specific technology.
    Thanks in advance.
    ravi.

    follow this tutorial and you might get some clues: http://java.sun.com/docs/books/tutorial/networking/sockets/index.html

  • Chat  Application Architecture

    Hello ,
    Can anybody help me out about what could be the best architecture for developing a chat application like MSN Messenger (for intranet as well as if possible for the internet as well).
    I know Java & JSP can be very useful but can anybody tell me more clearly that what threading issues and client-to-server or server-to-server communication should be taken into consideration ??
    Please help me in detail.
    Thx in advance
    [email protected]

    first of all, don't crosspost (forgive me if you didn't but i recall seeing exactly same topic in another forum)
    and how to do it?
    if you want t have think like MSN, then you'd need to have something peer-2-peer alike... that each client is also server and then they "speak" to each other directly.
    but other version would be such, that each client has only client socket, with which it connects to server application, that propagates chat from one client to everyone...
    that server could then become a bottle-neck for your chat if you have lot's of clients, but then again, you might not have that much clients in intranet.

  • Help wanted: Building jsp chat

    Hi!
    I am currently working on a school project where we're building a chat. We use jsp as server side programming language.
    We store the messages in a MySQL database.
    Now to the problem:
    We want the message window to be updated everytime any user writes something eg. the user can see when someone writes something. We have thought of using the HTML meta tag "refresh", but there has to be a better way? Got any ideas?
    Thanks
    *j.ett5

    Personally I am not sure that I would use JSP to build a chat application because JSP was not really meant for interactive user responses. If you are using JSP because the assignment requires JSP then I understand.
    I would consider creating some sort of simple client-side applet that interacts with a serverside java app. This might require a little more work because you would have to work out some sort of simple protocol and pass the data over via a socket connection, but doesnt that sound like fun? :) The server side app could still query the DB but it would also be able to update client applets.
    Seriously though, if you have to use JSP then I would agree that your best bet at refreshing entries would be to use the HTTP refresh meta tag. For best performance you will want to make sure that if no new entries to the DB have been added since the last refresh that you simply send a static version of the last page so that JSP doesnt have to build the page every time each clients web browser refreshes.

  • How do i develop a chat application using jms over web based

    I want to develop a chat application using jms with mailing,file transfer and audio facilities
    can anyone help me to how to go abt that

    There is a good article from Sun on a simple example of what you want - it could serve as a basis for you.
    http://developer.java.sun.com/developer/technicalArticles/peer/

  • 3GS Voice Chat Application

    Hey I'm looking for a specific voice chat application. I would like an app that would allow multiple users to join a chat room and talk via voice with each other on the iphone. I would like this app to also allow users on a PC to join into this voice chat with iphone users. I would also like to make the chat room private so only certain users can join the chat room. Is there an existing application that accomplishes this? I have searched around the internet and haven't found anything yet. Thanks.

    Stebalien wrote:Cool! However, the key exchange system looks a little unwieldy; personally, I would give everyone a permanent "identity" key (preferably allow the user to a GPG key) and then use the socialist millionaire's protocol (SMP) to exchange these keys. Once the keys have been exchanged, they can be used to negotiate shared session keys. This way, once you talk to someone once, you don't need to keep manually sharing a key with them. The OTR library (libotr) does this very well but I don't know how usable it would be for this project (it's intended for layering encryption over existing IM protocols).
    Really thanx for your interest, i refer to the main developer . Be free to come in #seren on irc.freenode.net , to talk directly with him and the community!

  • What are the requirements to build a live video chat application?

    I am looking into making a live video chat application. I
    have seen several examples on the web so my question is not "how"
    to do it. My question is "what do I need" to do it?
    It seems that all the examples use Flex Data Services and
    then some sort of back-end communication server. The cost of FDS is
    well beyond what the client can afford so my question is: is it
    necessary? Is there a way to build this sort of application without
    FDS? Can I get live video streaming to work using only what is in
    the SDK? I know nothing about data streaming, real-time
    communication, etc. and have no idea how to implement this outside
    what I have seen in the online articles so far.
    If there are any other forums that are more appropriate to
    this question, please direct me there. It is not a FDS exclusive
    issue and I am just starting to look into it. I am starting here
    because we would like to use Flash Player for the client-side
    application.

    I am looking into making a live video chat application. I
    have seen several examples on the web so my question is not "how"
    to do it. My question is "what do I need" to do it?
    It seems that all the examples use Flex Data Services and
    then some sort of back-end communication server. The cost of FDS is
    well beyond what the client can afford so my question is: is it
    necessary? Is there a way to build this sort of application without
    FDS? Can I get live video streaming to work using only what is in
    the SDK? I know nothing about data streaming, real-time
    communication, etc. and have no idea how to implement this outside
    what I have seen in the online articles so far.
    If there are any other forums that are more appropriate to
    this question, please direct me there. It is not a FDS exclusive
    issue and I am just starting to look into it. I am starting here
    because we would like to use Flash Player for the client-side
    application.

  • Frame issue in jsp/struts application

    I have a problem with jsp struts application .
    i have a jsp page which is inside a frame .
    The action class which receives the request from this page redirects the request to another jsp page.
    I want this new jsp page to be displayed without any frame , but it is getting displayed from inside the frame .
    can anybody help me out ...
    regards,               
    slam

    Possibly:
    1. Browser could be caching the page.
    2. If you use a proxy, the proxy may be caching the page.
    3. The page is not getting recompiled.

  • Urgent need of help with a chat application!

    Hi,
    I'm writing a Chat Application and I want to add Emoticon, I did so by adding buttons but I don't know how to send the gif to my JTextField and to my JTextArea.
    Here is part of my code can someone can help me PLEASE!!!
    JPanel chatPane = new JPanel(new BorderLayout());
    JPanel emoticon = new JPanel(new GridLayout(2, 5));
    b1 = new JButton (sourrire);
    b1.setToolTipText("Un Sourire");
    // b1.addActionListener();
    emoticon.add(b1);
    b2 = new JButton (gsourrire);
    b2.setToolTipText("Un Grand Sourire");
    // b2.addActionListener();
    emoticon.add(b2);
    b3 = new JButton (triste);
    b3.setToolTipText("Triste");
    // b3.addActionListener();
    emoticon.add(b3);
    b4 = new JButton (grimace);
    b4.setToolTipText("Grimace");
    // b4.addActionListener();
    emoticon.add(b4);
    b5 = new JButton (pleure);
    b5.setToolTipText("Pleure");
    // b5.addActionListener();
    emoticon.add(b5);
    b6 = new JButton (bec);
    b6.setToolTipText("Un bec");
    // b6.addActionListener();
    emoticon.add(b6);
    b7 = new JButton (coeur);
    b7.setToolTipText("Un coeur pour toi");
    // b7.addActionListener();
    emoticon.add(b7);
    b8 = new JButton (fache);
    b8.setToolTipText("Fache");
    // b8.addActionListener();
    emoticon.add(b8);
    b9 = new JButton (lunettes);
    b9.setToolTipText("Je suis Cool");
    // b9.addActionListener();
    emoticon.add(b9);
    b10 = new JButton (clinoeil);
    b10.setToolTipText("Clin d'Oeil");
    //b10.addActionListener(new ActionAdapter2());
    emoticon.add(b10);
    Thanks a lot!
    Isabelle

    Hi anoopjain13
    what I did is that each button is an IconImage and I was trying to send the Icon to the textfield.
    here is the complete code of my chat, you'll understand better what I tried to do.
    //Naziha Berrassil et Isabelle Gosselin
    //Travail Pratique #1
    //remis � Said Senhaji
    //Developpement d'une application CHAT
    //package chatv2.a
    import java.lang.*;
    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    public class TCPChat2a implements Runnable {
    // Constantes de l'etat de la connection
    public final static int NULL = 0;
    public final static int DISCONNECTED = 1;
    public final static int DISCONNECTING = 2;
    public final static int BEGIN_CONNECT = 3;
    public final static int CONNECTED = 4;
    // Declaration d'un tableau de chaines
    public final static String statusMessages[] = {
    " Erreur! Aucune connexion possible!", " Deconnexion",
    " Deconnexion en cours...", " Connexion en cours...", " Connexion"
    //Instentiation de la classe
    public final static TCPChat2a tcpObj = new TCPChat2a();
    // Indique la fin d'une session
    public final static String END_CHAT_SESSION =
    new Character((char)0).toString();
    // Informations sur l'etat de la connexion
    public static String hostIP = "localhost";
    public static String user = "";
    public static String s1;
    public static int port = 1234;
    public static int connectionStatus = DISCONNECTED;
    public static boolean isHost = true;
    public static String statusString = statusMessages[connectionStatus];
    public static StringBuffer toAppend = new StringBuffer("");
    public static StringBuffer toSend = new StringBuffer("");
    // Declaration des composantes GUI et initialisation
    public final static ImageIcon sourrire = new ImageIcon ("icons/sourrire.gif");
    public static JButton b1;
    public final static ImageIcon gsourrire = new ImageIcon ("icons/grand_sourrire.gif");
    public static JButton b2;
    public final static ImageIcon triste = new ImageIcon ("icons/triste.gif");
    public static JButton b3;
    public final static ImageIcon pleure = new ImageIcon ("icons/pleure.gif");
    public static JButton b4;
    public final static ImageIcon coeur = new ImageIcon ("icons/coeur.gif");
    public static JButton b5;
    public final static ImageIcon grimace = new ImageIcon ("icons/grimace.gif");
    public static JButton b6;
    public final static ImageIcon lunettes = new ImageIcon ("icons/lunettes.gif");
    public static JButton b7;
    public final static ImageIcon fache = new ImageIcon ("icons/fache.gif");
    public static JButton b8;
    public final static ImageIcon bec = new ImageIcon ("icons/bec.gif");
    public static JButton b9;
    public final static ImageIcon clinoeil = new ImageIcon ("icons/clinoeil.gif");
    public static JButton b10;
    public static JFrame mainFrame = null;
    public static JTextArea chatText = null;
    public static JTextField chatLine = null;
    public static JPanel statusBar = null;
    public static JLabel statusField = null;
    public static JTextField statusColor = null;
    public static JTextField ipField = null;
    public static JTextField username = null;
    public static JTextField portField = null;
    public static JRadioButton hostOption = null;
    public static JRadioButton guestOption = null;
    public static JButton connectButton = null;
    public static JButton disconnectButton = null;
    // Declaration des composantes TCP
    public static ServerSocket hostServer = null;
    public static Socket socket = null;
    public static BufferedReader in = null;
    public static PrintWriter out = null;
    //Methode qui retourne le premier pannel(optionsPane),ce dernier
    //se compose de 5 panneaux
    private static JPanel initOptionsPane() {
    //pannel pane qui sera ajout� au pannel optionsPane
    JPanel pane = null;
    //initiation de la classe ActionAdapteur qui implemente ActionListner
    ActionAdapter buttonListener = null;
    // Creation du pannel optionsPane
    JPanel optionsPane = new JPanel(new GridLayout(5, 1));
    // 1er pannel pane pour label et textfield de l'adresse IP
    pane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    pane.add(new JLabel("Serveur IP:"));
    ipField = new JTextField(10);
    ipField.setBackground(new Color(0.98f, 0.97f, 0.85f));
    ipField.setText(hostIP);
    ipField.setEnabled(false);
    //evenement generer par Component avec la methode addFocusListener
    //en cas d'obtention ou perte du focus par un composant
    ipField.addFocusListener(new FocusAdapter() {
    public void focusLost(FocusEvent e) {
    ipField.selectAll();
    //Editable seulement en mode deconnexion
    if (connectionStatus != DISCONNECTED) {
    changeStatusNTS(NULL, true);
    else {
    hostIP = ipField.getText();
    pane.add(ipField);
    optionsPane.add(pane);
    // 2eme pannel pane pour label et textfield du port
    pane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    pane.add(new JLabel("Port:"));
    portField = new JTextField(10);
    portField.setBackground(new Color(0.98f, 0.97f, 0.85f));
    portField.setEditable(true);
    portField.setText((new Integer(port)).toString());
    portField.addFocusListener(new FocusAdapter() {
    public void focusLost(FocusEvent e) {
    //Textfield du port modifiable si on est en mode deconnexion
    if (connectionStatus != DISCONNECTED) {
    changeStatusNTS(NULL, true);
    else {
    int temp;
    try {
    temp = Integer.parseInt(portField.getText());
    port = temp;
    catch (NumberFormatException nfe) {
    portField.setText((new Integer(port)).toString());
    mainFrame.repaint();
    pane.add(portField);
    optionsPane.add(pane);
    // 3eme pannel pour label et textfield du nom d'utilisateur
         pane = new JPanel(new FlowLayout(FlowLayout.RIGHT));
              pane.add(new JLabel("Nom: "));
              username = new JTextField(10);
    username.setBackground(new Color(0.98f, 0.97f, 0.85f));
              username.setText(user);
              username.setEnabled(true);
              username.addFocusListener(new FocusAdapter() {
              public void focusLost(FocusEvent e) {
              // username.selectAll();
              // Should be editable only when disconnected
              if (connectionStatus != DISCONNECTED) {
              changeStatusNTS(NULL, true);
              else {
              user = username.getText();
              pane.add(username);
    optionsPane.add(pane);
    // Host/guest option
    buttonListener = new ActionAdapter() {
    public void actionPerformed(ActionEvent e) {
    if (connectionStatus != DISCONNECTED) {
    changeStatusNTS(NULL, true);
    else {
    isHost = e.getActionCommand().equals("host");
    // Cannot supply host IP if host option is chosen
    if (isHost) {
    ipField.setEnabled(false);
    ipField.setText("localhost");
    hostIP = "localhost";
    else {
    ipField.setEnabled(true);
    //creation de boutton groupe radio(serveur et invite)
    ButtonGroup bg = new ButtonGroup();
    hostOption = new JRadioButton("Serveur", true);
    hostOption.setMnemonic(KeyEvent.VK_S);
    hostOption.setActionCommand("host");
    hostOption.addActionListener(buttonListener);
    guestOption = new JRadioButton("Invite", false);
    guestOption.setMnemonic(KeyEvent.VK_I);
    guestOption.setActionCommand("invite");
    guestOption.addActionListener(buttonListener);
    bg.add(hostOption);
    bg.add(guestOption);
    // 4eme pannel pane pour les 2 bouttons radio
    pane = new JPanel(new GridLayout(1, 2));
    pane.add(hostOption);
    pane.add(guestOption);
    optionsPane.add(pane);
    // 5eme pannel buttonPane pour les bouttons de connexion et deconnexion
    JPanel buttonPane = new JPanel(new GridLayout(1, 2));
    buttonListener = new ActionAdapter() {
    public void actionPerformed(ActionEvent e) {
    // requete pou debut d'une connexion
    if (e.getActionCommand().equals("connect")) {
    changeStatusNTS(BEGIN_CONNECT, true);
    // Deconnexion
    else {
    changeStatusNTS(DISCONNECTING, true);
    //creation des bouttons dans le pannel et l'ajout au premier pannel
    //(optionsPane)
    connectButton = new JButton("Connexion");
    connectButton.setMnemonic(KeyEvent.VK_C);
    connectButton.setActionCommand("connect");
    connectButton.addActionListener(buttonListener);
    connectButton.setEnabled(true);
    disconnectButton = new JButton("Deconnexion");
    disconnectButton.setMnemonic(KeyEvent.VK_D);
    disconnectButton.setActionCommand("disconnect");
    disconnectButton.addActionListener(buttonListener);
    disconnectButton.setEnabled(false);
    buttonPane.add(connectButton);
    buttonPane.add(disconnectButton);
    optionsPane.add(buttonPane);
    return optionsPane;
    // Initialisation de toutes les composantes GUI et affichage du frame
    private static void initGUI() {
    // Configuration du status bar
    // cr�ation d'un autre pannel statusBar qui se compose d'un petit carr�
    // color� et un label indiquant le mode de connexion
    statusField = new JLabel(); //Label indiquant l'�tat de la connexion
    statusField.setText(statusMessages[DISCONNECTED]);
    statusColor = new JTextField(1); //carr� color� indiquant l'�tat de la connection grace a des couleurs
    statusColor.setBackground(Color.red);
    statusColor.setEditable(false);
    statusBar = new JPanel(new BorderLayout());
    statusBar.add(statusColor, BorderLayout.WEST);
    statusBar.add(statusField, BorderLayout.CENTER);
    // Configuration du pannel optionsPane en appelant la methode d'initiation
    // de ce dernier
    JPanel optionsPane = initOptionsPane();
    // Creation et configuration du pannel chatPane qui contient un
    // textarea au centre avec une barre defilante verticale et un textfield
    // au sud pour faire rentrer les messages
    JPanel chatPane = new JPanel(new BorderLayout());
         JPanel emoticon = new JPanel(new GridLayout(2, 5));
    b1 = new JButton (sourrire);
    b1.setToolTipText("Un Sourire");
    // b1.addActionListener();
    emoticon.add(b1);
    b2 = new JButton (gsourrire);
    b2.setToolTipText("Un Grand Sourire");
    // b2.addActionListener();
    emoticon.add(b2);
    b3 = new JButton (triste);
    b3.setToolTipText("Triste");
    // b3.addActionListener();
    emoticon.add(b3);
    b4 = new JButton (grimace);
    b4.setToolTipText("Grimace");
    // b4.addActionListener();
    emoticon.add(b4);
    b5 = new JButton (pleure);
    b5.setToolTipText("Pleure");
    // b5.addActionListener();
    emoticon.add(b5);
    b6 = new JButton (bec);
    b6.setToolTipText("Un bec");
    // b6.addActionListener();
    emoticon.add(b6);
    b7 = new JButton (coeur);
    b7.setToolTipText("Un coeur pour toi");
    // b7.addActionListener();
    emoticon.add(b7);
    b8 = new JButton (fache);
    b8.setToolTipText("Fache");
         // b8.addActionListener();
         emoticon.add(b8);
    b9 = new JButton (lunettes);
    b9.setToolTipText("Je suis Cool");
    // b9.addActionListener();
    emoticon.add(b9);
    b10 = new JButton (clinoeil);
    b10.setToolTipText("Clin d'Oeil");
    //b10.addActionListener(new ActionAdapter2());
    emoticon.add(b10);
    emoticon.addActionListener(new ActionAdapter() {
    public void actionPerformed(ActionEvent e) {
                             String image = chatLine.setImage().toString();
                             appendToChatBox(image);
                             chatLine.selectAll();
                             sendString(image)
                             chatLine.setText(" ");
    emoticon.setVisible(true);
    //b1 = setVisible(true);
    chatText = new JTextArea(10, 100);
    chatText.setBackground(new Color(0.98f, 0.97f, 0.85f));
    chatText.setLineWrap(true);
    chatText.setEditable(false);
    chatText.setForeground(Color.blue);
    JScrollPane chatTextPane = new JScrollPane(chatText,
    JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
    JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    chatLine = new JTextField(10);
    chatLine.setBackground(new Color(0.98f, 0.97f, 0.85f));
    chatLine.setForeground(Color.blue);
    chatLine.setEnabled(false);
    chatLine.addActionListener(new ActionAdapter() {
    public void actionPerformed(ActionEvent e) {
    String s = chatLine.getText();
    if (!s.equals("")) {
    appendToChatBox(user=username.getText()+" dit : \n" + s + "\n");
    chatLine.selectAll();
    // Envoi de la chaine entr�e
    sendString(s);
    chatLine.setText("");
    chatPane.add(chatLine, BorderLayout.SOUTH);
    chatPane.add(chatTextPane, BorderLayout.NORTH);
    chatPane.setPreferredSize(new Dimension(300, 300));
         chatPane.add(emoticon, BorderLayout.CENTER);
    // Ajout des pannels dans le pannel principal (mainPane)
    JPanel mainPane = new JPanel(new BorderLayout());
    mainPane.add(statusBar, BorderLayout.SOUTH);
    mainPane.add(optionsPane, BorderLayout.WEST);
    mainPane.add(chatPane, BorderLayout.CENTER);
    // Configuration du frame (mainFrame)
    mainFrame = new JFrame("Chat");
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    // la m�thode setDefaultCloseOperation(int)provient de la classe javax.swing.JDialog
         // Elle specifi l'op�ration qui sera ex�cut�e par d�fault lorsque
         // l'utilisateur initialisera une fermeture de session
    mainFrame.setContentPane(mainPane);
    mainFrame.setSize(mainFrame.getPreferredSize());
         // la m�thode getPreferredSize() provient de la classe java.awt
         // Retourne la grosseur "pr�f�r�e" du container.
    mainFrame.setLocation(200, 200);
    // la m�thode setLocation(double, double) provient de la classe java.awt.Point
         // elle permet de specifiez un emplacement d'un point a des coordonn�es de type Float
    mainFrame.pack();
    // la m�thode pack() provient de la class AWT.Window, elle permet a la fenetre
    // d'�tre ajuster a la grosseur et a la mise en page des sous-composantes de celle-ci
    mainFrame.setVisible(true);
    // Le thread qui permet le changement des composantes GUI pendant le
    // changement de l'etat
    private static void changeStatusTS(int newConnectStatus, boolean noError) {
    // Changer l'etat si valide
    if (newConnectStatus != NULL) {
              connectionStatus = newConnectStatus;
    // S'il n'y a aucunes erreur, afficher le bon message de l'etat
    if (noError) {
    statusString = statusMessages[connectionStatus];
    // Autrement, afficher le message d'erreur
    else {
    statusString = statusMessages[NULL];
    System.out.println("Echec lors de la connexion");
    // Appel a la routine de run()(Runnable interface) sur la gestion des erreurs
    // et la mise a jours des composantes GUI grace au thread
    SwingUtilities.invokeLater(tcpObj);
    // Le changement des composantes GUI sans aucun pendant le
    // changement de l'etat
    private static void changeStatusNTS(int newConnectStatus, boolean noError) {
    // Changer l'etat si valide
    if (newConnectStatus != NULL) {
    connectionStatus = newConnectStatus;
    // S'il n'y a aucunes erreur, afficher le bon message de l'etat
    if (noError) {
    statusString = statusMessages[connectionStatus];
    // Autrement, afficher le message d'erreur
    else {
    statusString = statusMessages[NULL];
    // Appel a la routine de run()(Runnable interface) sur la gestion des erreurs
    // en utilisant le thread
    tcpObj.run();
    // L'ajout au chat box avec l'utilisation du Thread
    private static void appendToChatBox(String s) {
    synchronized (toAppend) {
    toAppend.append(s);
    System.out.println(s);
    // Ajouter le text au "send-buffer"
    private static void sendString(String s) {
    synchronized (toSend) {
    toSend.append(user=username.getText()+ " dit : \n" + s + "\n");
    // Nettoyage pour le debranchement
    private static void cleanUp() {
    try {
    if (hostServer != null) {
    hostServer.close();
    hostServer = null;
    catch (IOException e) { hostServer = null; }
    try {
    if (socket != null) {
    socket.close();
    socket = null;
    catch (IOException e) { socket = null; }
    try {
    if (in != null) {
    in.close();
    in = null;
    catch (IOException e) { in = null; }
    if (out != null) {
    out.close();
    out = null;
    // Verification de l'etat courrant et ajustement de "enable/disable"
    // en fonction de l'etat
    public void run() {
    switch (connectionStatus) {
    case DISCONNECTED:
    connectButton.setEnabled(true);
    disconnectButton.setEnabled(false);
    ipField.setEnabled(true);
    portField.setEnabled(true);
    username.setEnabled(true);
    hostOption.setEnabled(true);
    guestOption.setEnabled(true);
    chatLine.setText("");
    chatLine.setEnabled(false);
    statusColor.setBackground(Color.red);
    break;
    case DISCONNECTING:
    connectButton.setEnabled(false);
    disconnectButton.setEnabled(false);
    ipField.setEnabled(false);
    portField.setEnabled(false);
    hostOption.setEnabled(false);
    guestOption.setEnabled(false);
    chatLine.setEnabled(false);
    statusColor.setBackground(Color.orange);
    break;
    case CONNECTED:
    connectButton.setEnabled(false);
    disconnectButton.setEnabled(true);
    ipField.setEnabled(false);
    portField.setEnabled(false);
    hostOption.setEnabled(false);
    username.setEnabled(false);
    guestOption.setEnabled(false);
    chatLine.setEnabled(true);
    statusColor.setBackground(Color.green);
    break;
    case BEGIN_CONNECT:
    connectButton.setEnabled(false);
    disconnectButton.setEnabled(false);
    ipField.setEnabled(false);
    portField.setEnabled(false);
    hostOption.setEnabled(false);
    username.setEnabled(false);
    guestOption.setEnabled(false);
    chatLine.setEnabled(true);
    chatLine.grabFocus();
    statusColor.setBackground(Color.orange);
    break;
    // S'assurer que l'etat des champs bouton/texte sont consistent
    // avec l'etat interne
    ipField.setText(hostIP);
    portField.setText((new Integer(port)).toString());
    hostOption.setSelected(isHost);
    guestOption.setSelected(!isHost);
    statusField.setText(statusString);
    chatText.append(toAppend.toString());
    toAppend.setLength(0);
    mainFrame.repaint();
    // Procedure principale
    public static void main(String args[]) {
    String s;
    initGUI();
    while (true) {
    try {
    Thread.sleep(10);
         // Verification a toute les 10 ms
    catch (InterruptedException e) {}
    switch (connectionStatus) {
    case BEGIN_CONNECT:
    try {
    // Essai de configuration du serveur si "host"
    if(user != ""){
         if (isHost) {
         hostServer = new ServerSocket(port);
         socket = hostServer.accept();
         // Si invit�, essai de branchement au serveur
         else {
         socket = new Socket(hostIP, port);
    in = new BufferedReader(new
    InputStreamReader(socket.getInputStream()));
    out = new PrintWriter(socket.getOutputStream(), true);
    changeStatusTS(CONNECTED, true);
    System.out.println("Ouverture de la session: \n" + socket);
              else{
              JOptionPane.showMessageDialog(null, "Erreur, vous devez entrer un nom d'utilisateur", "Erreur", JOptionPane.PLAIN_MESSAGE);
                        changeStatusTS(DISCONNECTED, false);
    // Si erreur, nettoyage et envoi du message d'erreur
    catch (IOException e) {
    cleanUp();
    changeStatusTS(DISCONNECTED, false);
    break;
    case CONNECTED:
    try {
    // Envoi de data
    if (toSend.length() != 0) {
    out.print(toSend);
    out.flush();
    toSend.setLength(0);
    changeStatusTS(NULL, true);
    // Reception de data
    if (in.ready()) {
    s = in.readLine();
    if ((s != null) && (s.length() != 0)) {
    // Verification de la fin de la transmission
    if (s.equals(END_CHAT_SESSION)) {
    changeStatusTS(DISCONNECTING, true);
    // Autrement, reception du texte
    else {
    appendToChatBox( s + "\n");
    changeStatusTS(NULL, true);
    catch (IOException e) {
    cleanUp();
    changeStatusTS(DISCONNECTED, false);
    break;
    case DISCONNECTING:
    // Dis aux autres fenetre de chat de se d�brancher aussi
    out.print(END_CHAT_SESSION);
    out.flush();
                   System.out.println("Fermeture de la session");
    // Nettoyage (ferme les streams/sockets)
    cleanUp();
    changeStatusTS(DISCONNECTED, true);
    break;
    default: break; // ne fait rien
    // Certaines interfaces �couteurs sont accompagn�es d'adaptateurs qui
    //implementent toutes les methodes de l'interface et evitent de les lister.
    class ActionAdapter implements ActionListener {
    public void actionPerformed(ActionEvent e) {}
    ////////////////////////////////////////////////////////////////////

  • Close a client part of the socket in a chat application

    Hy. I have a chat application where the clients connect to the server. For example lets suppose that there are 3 clients connected to the server. I want to make a method that makes the followings : when a client wants to disconnect from the chat application(from the server) he types 'disconnect', and the connection between server and client is interrupted. How can i do this????

    Here is the exceptionjava.net.SocketException: Socket closed
         at java.net.SocketInputStream.socketRead0(Native Method)
         at java.net.SocketInputStream.read(SocketInputStream.java:129)
         at java.net.SocketInputStream.read(SocketInputStream.java:182)
         at java.io.DataInputStream.readInt(DataInputStream.java:370)
         at chat.common.network.MessageReader.unserializedMessage(MessageReader.java:38)
         at chat.common.network.MessageReader.run(MessageReader.java:29)
         at java.lang.Thread.run(Thread.java:619), and MessageReader class is like this
    public class MessageReader implements Runnable {
        private SynchronizedQueue<IMessage> list;
        private DataInputStream in;
        private static boolean running = true;
        public MessageReader(SynchronizedQueue<IMessage> list, InputStream in) {
            this.list = list;
            this.in = new DataInputStream(in);
        public static void isRunning(boolean isRunning) {
            running = isRunning;
        public void run() {
            try {
                while (running) {
                    IMessage m = unserializedMessage(in);
                    list.offer(m);
            } catch (IOException e) {
                e.printStackTrace();
        private IMessage unserializedMessage(DataInputStream in) throws IOException {
            int type = in.readInt();
            IMessage m;
            try {
                m = MessageFactory.create(type);
            } catch (Exception e) {
                throw new IOException("userialize exc " + e.getMessage());
            m.unserialize(in);
            return m;
    } This

  • Doubts over the Performance in Developing a Chat application

    We are developing a chat application which needs to update the chat content in the database for the duration of the chat (ie.,For the duration of a session).At the same time the page should refresh and show the current content on both ends.In addition to both these, the database tables has to be checked to detect the occurence of a Network error on both sides.
    We have developed it as a Browser based chat and we have used PHP with MySQL. The performance is slow.
    Can anyone give a suggestion as to whether we can develop the chat application completely from the scratch and if we do that which technology should we choose to boost the performance.
    If anyone is not clear about my problem just mail me.I'll explain it in more detail.
    Thanks in Advance

    Hi,
    I just wanted to know these following answers.
    2) Network failure -- Means (either browswer got killed or data did not arrived/Page Not refreshed)
    3) which WebSErver are U using?
    From java, it is very easy to develop chatting application for which you can use applet and servlets for the same (if you consider the performance is the utmost importance)
    Updating to the database should not be done for the duration levels rather should be done at the event levels(data change/keyboards/session -inf changes).
    Im not sure about PHPs running at client but I can suggest you to use two frames .One is for typing and other one is for displaying information which basically gets the staus from the server abt other users in the chat either from the session, which would be driven by other component which is static) .
    Any how, I just put my ideas (Im sure , you know all these things)
    with regards
    Lokesh T.c

  • Implementation of type-ahead functionality in Endeca JSP Ref application

    Hi all,
    I am trying to implement the type-ahead functionality in Endeca jsp reference application which Oracle is shipping with it's products. The type-ahead functionality is not present by default. Can anyone help me to implement the same thing or provide sample code/strategy to achieve the desired results ?
    Basically typeahead functionality is present in Endeca Information's quick start's search box (EID) but not it JSP reference application .
    Waiting for the replies...
    Regards,
    Hoque

    Type-ahead functionality can mean different things and be implemented in different ways. It is usually based on what behavior your user-space would benefit from.
    In the commerce space, one popular use-case is to return Category matches based on what a user has started typing. Within Endeca, this boils down to doing a dimension search and having the Category dimension enabled for dimension search. If a user starts typing "cam", the type-ahead would then recommend:
    Category: Cameras
    You can match on multiple dimensions though, so long as they are enabled for dimension search. For example, if a user starts typing "ca", the type-ahead could return:
    Category: Cameras
    Brand: Canon
    Furthermore, this behavior can be extended by enabling Compound Dimension Search. Compound Dimension Search is enabled via a flag on the dgidx process and on your ENEQuery. It provides the following behavior. If a user searches for "canon cam", it would suggest:
    Category: Cameras + Brand: Canon
    Clicking on the type-ahead would return the intersection of Category = Cameras and Brand = Canon, eliminating a click if the user is after Canon brand Cameras.
    With regards to implementation, it basically boils down to an AJAX call to a service/URL that responds with dimension search results. Then populate an empty &lt;div&gt; with links.
    Other scenarios involve returning Product/Record matches instead of Dimension matches.
    Edited by: gose on Sep 11, 2012 8:31 AM

  • Best way to manage images on jsp web application

    Hi,
    Am developing a jsp web application, in that project, the user will upload the image files, now I created an image directory in the context root and when the image is uploaded by the user it is saved in the /images directory and the image path is saved in the database. I can display this image using the <img src="images/a.jsp" > tag.
    but when I rebuild the project all the images in the /images directory get deleated but the image path is remained in the database, is there any method that I make /image dir outside my project context root so that when I rebuild the project the /images dir can get changed and my project will save images outside the context root that is in the /images dir which is now outside the project context root. and is it possible to display those images using <img src""> tag. because this time my /images dir is at D:/images . what could be the best method or way to handle images with the web application.
    any suggestion will be helpfull

    Well my friend as per your given case there are to two ways of approaching your problem.
    Case 1:
    How to save the relevant data ??
    .Create a backup folder Workstation on which you are hosting your application where you can store all the uploaded files which is outside the scope of webserver(However we can write a dedicated servlet which can access that file) and make sure we pickup from any the folder path from a specfic MessageResource bundle or an context/servlet init parameter in web.xml.
    .Write a Upload servlet/Backing Bean which saves all the files in the discussed folder using utility packages like Commons FileUpload,Oreilly MultipartRequest & etc and then register saved fileName in the database user specfic table specific to user.
    How to display the Image ??
    .Write a dedicated servlet which can pickup user related fileName specfic information from the database and the read the file from backup folder by constructing the path from the entry made as a init param in web.xml or any other custom MessageResource bundle and then stream the Image data using the ServletOutputStream.
    NOTE: do not forget to pickup & setImage file ContentType & Set the content length.
    .Just try to render the JSP view file where we are displaying the displaying the images by calling the dedicated ImageServlet.
    <img src="ImageServlet?userid=2345" align="center"/>Try to refer below posts to get a better understading.
    Dedicated Image Servlet:
    http://forum.java.sun.com/thread.jspa?threadID=5208858&messageID=9840042#9840042
    Uploading Files Using Servlet:
    http://muimi.com/j/jakarta/commons/fileupload/
    Case 2
    The second method would more or less the same but here we would save the uploaded file
    content is saved in the Database as a Blob and we would retrive it back using a dedicated image servlet again.
    However,in terms of performance the second case implementation is very costly.
    Try to refer below posts to get a better understading on the second case.
    http://forum.java.sun.com/thread.jspa?threadID=5193481&tstart=50
    http://forum.java.sun.com/thread.jspa?threadID=5211649&messageID=9853670#9853670
    Hope this might help :)
    REGARDS,
    RaHuL

  • Recommendations for a simple, fast GUI LAN chat application? [Solved]

    We now have 4 ArchLinux machines scattered throughout the house. (My wife is an Archer now!). I am looking for a simple fast GUI LAN chat application. I looked at "qchat" but it is a bit cumbersome and doesn't have the option of a small applet to the panel. Any recommendations appreciated...
    Larry
    Last edited by lagagnon (2010-02-13 21:27:00)

    jwwolf wrote:Found this in AUR
    griv
    I just tried it with a few machines and it works fine.
    Excellent choice! Nice, light and unobtrusive. Works well, thanks for the recommendation.

Maybe you are looking for

  • Logging in to my router

    Please help.  I am trying to change my existing encryption code to a more user friendly code.  I have attempted to log in to my router by going to http://192.168.1.1/ and leaving the user name blank and typing "admin" which is what I read was the rig

  • I am looking for NIST as well as FIPS Publications pertaining to the OS X Mountain Lion

    My IT deptartment is looking guidelines as well as standards from NIST and FIPS regarding using OS X Mountain Lion for government business.

  • Installshield, Basic MSI or installshieldscript

    Hello, I'm normally use Wise package studio to create normal windows msi packages. Now we have to pay for upgrade to support windows 2008 operating system. I trying to get some feeling with installshield because that's free for us (in combination wit

  • Icloud inop since update to 3.0

    Since icloud control panel updated to 3.0 & iTunes to 11.1.0.126, neither icloud control panel nor iTunes store works. iCloud control panel locks up and never connects to the server to download information although my apple id shows correctly.  Task

  • Standard function support for bond issueing?

    Dear all, Within Treasury and Risk Management, are there some standard functions to handle bond issueing? The requirement is mainly to record information of bond details, interest payment and repayment, and currently we don't take postings to GL and