Servlet chat server

Hello,
Is it possible to use a servlet as chat server? I created a chat system based on java and sockets now can I use servlet instead of chat server?
Thanks for your time.

Hi!
The Chat Server is an application where users can meet each other and handle a full controlled and organized conversation processes.
The Chat Server has its own techniques which must be understood by its creator, and it seems you were, bcz you've created a one.
With servlets, you can create a Web Applications, that means, an application that can accept http requests and generate http responses. In this architicture, the Web Application is stored (installed) in the middle, and then, it is surrounded by unlimited number of clients.
In your example, the Chat Server is the Web Application in the middle, and the chatters and moderators are surrounding this center in way you can control their communications and chat issues, they are clients.
Servlets gives the WEB behavior to your system, this means, the client should communicate with the system using HTTP protocol. And now with HTTP requests you can pass all required parameters to your Chat Server and then make the business logic tier which controls the chat issues.
So, of course you can. And peer in mind, that servlets will be accessed using HTTP specs via submitting URL's using the required HTTP methods (GET, POST, PUT,....), you can use the known HTTP methods to communicate with the servlets, I think it is a good idea to have a look at: http://jakarta.apache.org/commons/httpclient/ where you can find an open source Java API used for all http-client processes and function implementations.
Good luck.

Similar Messages

  • J2ME J2EE(servlet jsp) chat server

    want to make a chat server using J2ME(fronend) and J2EE(server) . Could anybdy tell me some sample applications on the net or tutorials that can help

    Darryl.Burke wrote:
    Why, is Google broken?Hey you dont have to be rude to the guy ... suggest a few or dont reply

  • Tomcat crashes while running servlet chat in IE

    Hi all!
    I've seen similar problems posted about three years ago, but I didn't see an answer for it.
    I'd be very grateful if you could help me.
    I'm writing a chat, the code was taken from the J.Hunter "Servlet programming book" O'reilly, "absurdly simple chat", and adjusted (I only need the Http version). It's an applet-servlet chat.
    When executed in IE, Tomcat crashes after a few (usually 5) sent messages. When executed in a debugger (I use Forte, the last available version, 4 update 1) the program works just fine...
    Another question is about debugging an applet, executed in a browser - how do I do this?
    Here is the code for the servlet:
    =================================
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class TryChatServlet extends HttpServlet
    // source acts as the distributor of new messages
    MessageSource source = new MessageSource();
    // doGet() returns the next message. It blocks until there is one.
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    // Return the next message (blocking)
    out.println(getNextMessage());
    // doPost() accepts a new message and broadcasts it to all
    // the currently listening HTTP and socket clients.
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    // Accept the new message as the "message" parameter
    String message = req.getParameter("message");
    // Broadcast it to all listening clients
    if (message != null) broadcastMessage(message);
    // Set the status code to indicate there will be no response
    res.setStatus(res.SC_NO_CONTENT);
    // getNextMessage() returns the next new message.
    // It blocks until there is one.
    public String getNextMessage() {
    // Create a message sink to wait for a new message from the
    // message source.
    return new MessageSink().getNextMessage(source);
    // broadcastMessage() informs all currently listening clients that there
    // is a new message. Causes all calls to getNextMessage() to unblock.
    public void broadcastMessage(String message) {
    // Send the message to all the HTTP-connected clients by giving the
    // message to the message source
    source.sendMessage(message);
    // MessageSource acts as the source for new messages.
    // Clients interested in receiving new messages can
    // observe this object.
    class MessageSource extends Observable {
    public void sendMessage(String message) {
    setChanged();
    notifyObservers(message);
    // MessageSink acts as the receiver of new messages.
    // It listens to the source.
    class MessageSink implements Observer {
    String message = null; // set by update() and read by getNextMessage()
    // Called by the message source when it gets a new message
    synchronized public void update(Observable o, Object arg) {
    // Get the new message
    message = (String)arg;
    // Wake up our waiting thread
    notify();
    // Gets the next message sent out from the message source
    synchronized public String getNextMessage(MessageSource source) {
    // Tell source we want to be told about new messages
    source.addObserver(this);
    // Wait until our update() method receives a message
    while (message == null) {
    try { wait(); } catch (Exception ignored) { }
    // Tell source to stop telling us about new messages
    source.deleteObserver(this);
    // Now return the message we received
    // But first set the message instance variable to null
    // so update() and getNextMessage() can be called again.
    String messageCopy = message;
    message = null;
    return messageCopy;
    =============================
    The code for the applet is
    =============================
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class TryChatApplet extends Applet implements Runnable {
    TextArea text;
    Label label;
    TextField input;
    Thread thread;
    String user;
    public void init() {
    // Check if this applet was loaded directly from the filesystem.
    // If so, explain to the user that this applet needs to be loaded
    // from a server in order to communicate with that server's servlets.
    URL codebase = getCodeBase();
    if (!"http".equals(codebase.getProtocol())) {
    System.out.println();
    System.out.println("*** Whoops! ***");
    System.out.println("This applet must be loaded from a web server.");
    System.out.println("Please try again, this time fetching the HTML");
    System.out.println("file containing this servlet as");
    System.out.println("\"http://server:port/file.html\".");
    System.out.println();
    System.exit(1); // Works only from appletviewer
    // Browsers throw an exception and muddle on
    // Get this user's name from an applet parameter set by the servlet
    // We could just ask the user, but this demonstrates a
    // form of servlet->applet communication.
    user = getParameter("user");
    if (user == null) user = "anonymous";
    // Set up the user interface...
    // On top, a large TextArea showing what everyone's saying.
    // Underneath, a labeled TextField to accept this user's input.
    text = new TextArea();
    text.setEditable(false);
    label = new Label("Say something: ");
    input = new TextField();
    input.setEditable(true);
    setLayout(new BorderLayout());
    Panel panel = new Panel();
    panel.setLayout(new BorderLayout());
    add("Center", text);
    add("South", panel);
    panel.add("West", label);
    panel.add("Center", input);
    public void start() {
    thread = new Thread(this);
    thread.start();
    String getNextMessage() {
    String nextMessage = null;
    while (nextMessage == null) {
    try {
    URL url = new URL(getCodeBase(), "/servlet/TryChatServlet");
    HttpMessage msg = new HttpMessage(url);
    InputStream in = msg.sendGetMessage();
    DataInputStream data = new DataInputStream(
    new BufferedInputStream(in));
    nextMessage = data.readLine();
    catch (SocketException e) {
    // Can't connect to host, report it and wait before trying again
    System.out.println("Can't connect to host: " + e.getMessage());
    try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
    catch (FileNotFoundException e) {
    // Servlet doesn't exist, report it and wait before trying again
    System.out.println("Resource not found: " + e.getMessage());
    try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
    catch (Exception e) {
    // Some other problem, report it and wait before trying again
    System.out.println("General exception: " +
    e.getClass().getName() + ": " + e.getMessage());
    try { Thread.sleep(1000); } catch (InterruptedException ignored) { }
    return nextMessage + "\n";
    public void run() {
    while (true) {
    text.appendText(getNextMessage());
    public void stop() {
    thread.stop();
    thread = null;
    void broadcastMessage(String message) {
    message = user + ": " + message; // Pre-pend the speaker's name
    try {
    URL url = new URL(getCodeBase(), "/servlet/TryChatServlet");
    HttpMessage msg = new HttpMessage(url);
    Properties props = new Properties();
    props.put("message", message);
    msg.sendPostMessage(props);
    catch (SocketException e) {
    // Can't connect to host, report it and abandon the broadcast
    System.out.println("Can't connect to host: " + e.getMessage());
    catch (FileNotFoundException e) {
    // Servlet doesn't exist, report it and abandon the broadcast
    System.out.println("Resource not found: " + e.getMessage());
    catch (Exception e) {
    // Some other problem, report it and abandon the broadcast
    System.out.println("General exception: " +
    e.getClass().getName() + ": " + e.getMessage());
    public boolean handleEvent(Event event) {
    switch (event.id) {
    case Event.ACTION_EVENT:
    if (event.target == input) {
    broadcastMessage(input.getText());
    input.setText("");
    return true;
    return false;
    =====================================
    HttpMessage
    ======================================
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class HttpMessage {
    URL servlet = null;
    String args = null;
    public HttpMessage(URL servlet) {
    this.servlet = servlet;
    // Performs a GET request to the previously given servlet
    // with no query string.
    public InputStream sendGetMessage() throws IOException {
    return sendGetMessage(null);
    // Performs a GET request to the previously given servlet.
    // Builds a query string from the supplied Properties list.
    public InputStream sendGetMessage(Properties args) throws IOException {
    String argString = ""; // default
    if (args != null) {
    argString = "?" + toEncodedString(args);
    URL url = new URL(servlet.toExternalForm() + argString);
    // Turn off caching
    URLConnection con = url.openConnection();
    con.setUseCaches(false);
    return con.getInputStream();
    // Performs a POST request to the previously given servlet
    // with no query string.
    public InputStream sendPostMessage() throws IOException {
    return sendPostMessage(null);
    // Performs a POST request to the previously given servlet.
    // Builds post data from the supplied Properties list.
    public InputStream sendPostMessage(Properties args) throws IOException {
    String argString = ""; // default
    if (args != null) {
    argString = toEncodedString(args); // notice no "?"
    URLConnection con = servlet.openConnection();
    // Prepare for both input and output
    con.setDoInput(true);
    con.setDoOutput(true);
    // Turn off caching
    con.setUseCaches(false);
    // Work around a Netscape bug
    con.setRequestProperty("Content-Type",
    "application/x-www-form-urlencoded");
    // Write the arguments as post data
    DataOutputStream out = new DataOutputStream(con.getOutputStream());
    out.writeBytes(argString);
    out.flush();
    out.close();
    return con.getInputStream();
    // Converts a Properties list to a URL-encoded query string
    private String toEncodedString(Properties args) {
    StringBuffer buf = new StringBuffer();
    Enumeration names = args.propertyNames();
    while (names.hasMoreElements()) {
    String name = (String) names.nextElement();
    String value = args.getProperty(name);
    buf.append(URLEncoder.encode(name) + "=" + URLEncoder.encode(value));
    if (names.hasMoreElements()) buf.append("&");
    return buf.toString();
    Those files are the only files needed to execute the program.

    The whole Tomcat crashes, and no exception
    displayed.
    Do I have to write the log file, or it's kept by
    Tomcat itself?yes, tomcat writes a log file, you find it in the tomcat dir. but it's just very highlevel. Having a look in it could help.
    Is there a way to write a log file by myself?sure. you could get the log file from tomcat by getting it from the ServletContext:
    ServletContext = getServletContext();
    ServletContext.log("text to log");
    When I view the output window in Forte, it doesn't
    even write that Tomcat crashed.
    I use Tomcat that is installed with the last version
    of Forte(Sun 1 Studio, update 1), I guess it's the
    last version of Tomcat also.No. The lastest is 4.1.12 and i guess it's 4.0.4 with forte.
    Get Tomcat standalone from jakarta.apache.org and try to run your servlet with the standalone tomcat. this could help since i also expirenced problems sometimes with the forte-integrated tomcat.

  • Applet like chat server

    Hi!
    I`m trying to do a chat server in applet whith sockets. I changed a chat server aplication to a applet but this server joing the browser.
    Is possible to do this? If not, how can i do a applet to talk whith another (peer-to-peer) without use socket?
    thanks for any help!
    Alexandre Camy

    Use a Servlet or JSP on the webserver to transmit messages from one peer applet to another applet

  • Trying to produce a java chat server

    Would like produce a working client/server chat system, as basic as possible but able to listen and talk to each other. Any chat servers how-to examples I've come across never seem to work.
    Would like to understand why applets don't work when I open the web page but do work when I view using the appletviewer. I use Internet Explorer 4 i think, java version 1.3.0_02
    would you understand at least part of this error which appears when I run a chat server
    exception:com.ms.security.SecurityExceptionEx[Client.<int>]:cannot access "194.81.104.26":5660
    (the error is all one line no spaces)
    the following code is one of the programs I've been working on and I receive the above error, appletviewer doesn't work so i think that means something is wrong with the code, client side as the server side works well, it listens etc
    // Client side
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    public class Client extends Panel implements Runnable
    // Components for the visual display of the chat windows
    private TextField tf = new TextField();
    private TextArea ta = new TextArea();
    // The socket connecting us to the server
    private Socket socket;
    // The streams we communicate to the server; these come
    // from the socket
    private DataOutputStream dout;
    private DataInputStream din;
    // Constructor
    public Client( String host,int port ) {
    // Set up the screen
    setLayout( new BorderLayout() );
    add( "North", tf );
    add( "Center", ta );
    // Receive messages when someone types a line
    // and hits return, using an anonymous class as
    // a callback
    tf.addActionListener( new ActionListener() {
    public void actionPerformed( ActionEvent e ) {
    processMessage( e.getActionCommand() );
    // Connect to the server
    try {
    // Initiate the connection
    socket = new Socket( host, port );
    // Recieved a connection
    System.out.println( "connected to "+socket );
    // Create DataInput/Output streams
    din = new DataInputStream( socket.getInputStream() );
    dout = new DataOutputStream( socket.getOutputStream() );
    // Start a background thread for receiving messages
    new Thread( this ).start();
    } catch( IOException ie ) { System.out.println( ie ); }
    // Called when the user types something
    private void processMessage( String message ) {
    try {
    // Send it to the server
    dout.writeUTF( message );
    // Clear out text input field
    tf.setText( "" );
    } catch( IOException ie ) { System.out.println( ie ); }
    // Background thread runs this: show messages from other window
    public void run() {
    try {
    // Receive messages one-by-one, forever
    while (true) {
    // Get the next message
    String message = din.readUTF();
    // Print it to our text window
    ta.append( message+"\n" );
    } catch( IOException ie ) { System.out.println( ie ); }
    // ClientApplet
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    public class ClientApplet extends Applet
    public void init() {
    //String host = getParameter( "host" );
         String host="194.81.104.26";
         //int port = Integer.parseInt( getParameter( "port" ) );
         int port =5660;
    setLayout( new BorderLayout() );
    add( "Center", new Client( host, port ) );
    // server
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Server
    // The ServerSocket is used for accepting new connections
    private ServerSocket ss;
    // A mapping from sockets to DataOutputStreams. This will
    // help us avoid having to create a DataOutputStream each time
    // we want to write to a stream.
    private Hashtable outputStreams = new Hashtable();
    // Constructor and while-accept loop all in one.
    public Server( int port ) throws IOException {
    // listening
    listen( port );
    private void listen( int port ) throws IOException {
    // Create the ServerSocket
    ss = new ServerSocket( port);
    // ServerSocket is listening
    System.out.println( "Listening on "+ss );
    // Keep accepting connections forever
    while (true) {
    // The next incoming connection
    Socket s = ss.accept();
    // Connection
    System.out.println( "Connection from "+s );
    // Create a DataOutputStream for writing data to the
    // other side
    DataOutputStream dout = new DataOutputStream( s.getOutputStream() );
    // Save this stream so we don't need to make it again
    outputStreams.put( s, dout );
    // Create a new thread for this connection, and then forget
    // about it
    new ServerThread( this, s );
    // Get an enumeration of all the OutputStreams, one for each client
    // connected to us
    Enumeration getOutputStreams() {
    return outputStreams.elements();
    // Send a message to all clients (utility routine)
    void sendToAll( String message ) {
    // We synchronise on this because another thread might be
    // calling removeConnection()
    synchronized( outputStreams ) {
    // For each client ...
    for (Enumeration e = getOutputStreams(); e.hasMoreElements(); ) {
    // ... get the output stream ...
    DataOutputStream dout = (DataOutputStream)e.nextElement();
    // ... and send the message
    try {
    dout.writeUTF( message );
    } catch( IOException ie ) { System.out.println( ie ); }
    // Remove a socket, and it's corresponding output stream, from our
    // list. This is usually called by a connection thread that has
    // discovered that the connectin to the client is dead.
    void removeConnection( Socket s ) {
    // Synchronise so sendToAll() is okay while it walks
    // down the list of all output streams
    synchronized( outputStreams ) {
    // Removing connection
    System.out.println( "Removing connection to "+s );
    // Remove it from our hashtable/list
    outputStreams.remove( s );
    // Make sure it's closed
    try {
    s.close();
    } catch( IOException ie ) {
    System.out.println( "Error closing "+s );
    ie.printStackTrace();
    // Main routine
    // Usage: java Server <port>
    static public void main( String args[] ) throws Exception {
    // Get the port # from the command line
    int port = Integer.parseInt( args[0] );
         //int port = 5000;
    // Create a Server object, which will automatically begin
    // accepting connections.
    new Server( port);
    // ServerThread
    import java.io.*;
    import java.net.*;
    public class ServerThread extends Thread
    // The Server that spawned
    private Server server;
    // The Socket connected to our client
    private Socket socket;
    // Constructor.
    public ServerThread( Server server, Socket socket ) {
    // Save the parameters
    this.server = server;
    this.socket = socket;
    // Start up the thread
    start();
    // This runs in a separate thread when start() is called in the
    // constructor.
    public void run() {
    try {
    // Create a DataInputStream for communication; the client
    // is using a DataOutputStream to write to us
    DataInputStream din = new DataInputStream( socket.getInputStream() );
    // Over and over, forever ...
    while (true) {
    // ... read the next message ...
    String message = din.readUTF();
    // ... sending printed to screen ...
    System.out.println( "Sending "+message );
    // ... and have the server send it to all clients
    server.sendToAll( message );
    } catch( EOFException ie ) {
    // This doesn't need an error message
    } catch( IOException ie ) {
    // This needs an error message
    ie.printStackTrace();
    } finally {
    // The connection is closed for one reason or another,
    // so have the server dealing with it
    server.removeConnection( socket );
    <body bgcolor="#FFFFFF">
    <applet code="ClientApplet" width=600 height=400>
    <param name=host value="127.0.0.1">
    <param name=port value="5660">
    [Chat applet]
    </applet>
    </body>

    Hi!
    Go to
    http://www.freecode.com/projects/jchat-java2clientserverchatmodule/
    probably u will het the answer..
    Jove

  • Lync 2010 client connecting to 2013 persistent chat server

    Since we never had Group Chat in our 2010 environment, I have no idea how it works and now that we have 2013 Persistent Chat, I am struggling with getting the Lync 2010 connected. The 2013 client works just fine as it is integrated into the client. I found
    out Lync 2010 needs a separate Chat client to run along side the IM client.
    I installed this client but from there I have no idea how to connect it to the 2013 Chat server. I created the endpoint on the Lync 2013 server according to the article
    http://technet.microsoft.com/en-us/library/jj204901.aspx but something else needs to be done. I just don't know what. Not even sure where to start looking. Many of our Lync clients have
    to use 2010 because the OS is XP so I need to find out how to get these users to work with Persistent Chat.
    I am not sure what the point is of creating the End point according to the article. I am sure its necessary but not sure how it fits into the clients using it to connect. What does the article mean when it says "Next, configure Persistent Chat clients
    to use that SIP address as their contact object". Do you need Group Chat functioning in 2010 for this to even work?
    The problem is we never had Group Chat with 2010 so I am sure there are some settings missing like DNS records etc...

    If you have users running legacy clients (such as Microsoft Lync 2010 these users might find the default Persistent Chat URIs difficult to work with and difficult to use when pointing their legacy client towards the pool. Because of this,
    administrators need to use the New-CsPersistentChatEndpoint cmdlet to create an additional contact object for the pool, a contact object that provides a friendlier, easier-to-use URI.
    Lisa Zheng
    TechNet Community Support

  • My simple chat server does not send messages to connected clients

    Hi!
    I´m developing a chat server. But I can not get it work. My client seems to make a connection to it, but my server does not send the welcome message it is supposed to send when a client connects. Why not?
    removedEdited by: Roxxor on Nov 24, 2008 10:36 AM

    Ok, I solved my previous problem and now I have got a new really annoying one.
    This is a broadcasting server which meand it can handle multiple clients and when one client sends a message to the server, the server should broadcast the message to all connected clients. It almost works, except that the server just sends the message back to the last connected client. The last connected client seems to steal the PrintStream() from the other clients. How can I solve that?
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.lang.Character;
    import java.io.OutputStream;
    import java.util.Vector;
    public class ChatServer extends MIDlet implements CommandListener, Runnable
         private Display disp;
         private Vector connection = new Vector();          
         private TextField tf_port = new TextField("Port: ", "", 32, 2);               
         private Form textForm = new Form("Messages");
         private Form start_serverForm = new Form("Start server", new Item[] {  tf_port });
         private Command mExit = new Command("Exit", Command.EXIT, 0);
         private Command mStart = new Command("Start", Command.SCREEN, 0);
         private Command mDisconnect = new Command("Halt server", Command.EXIT, 0);
         ServerSocketConnection ssc;
         SocketConnection sc;
         PrintStream out;
         public ChatServer()
              start_serverForm.addCommand(mExit);
              start_serverForm.addCommand(mStart);
              start_serverForm.setCommandListener(this);
              tf_port.setMaxSize(5);
              textForm.addCommand(mDisconnect);
              textForm.setCommandListener(this);
         public void startApp()
              disp = Display.getDisplay(this);
              disp.setCurrent(start_serverForm);
         public void pauseApp()
         public void destroyApp(boolean unconditional)
         public void commandAction(Command c, Displayable s)
              if(c == mExit)
                   destroyApp(false);
                   notifyDestroyed();
              else if(c == mStart)
                   Thread tr = new Thread(this);
                   tr.start();
              else if(c == mDisconnect)
                   try
                        sc.close();                              
                   catch(IOException err) { System.out.println("IOException error: " + err.getMessage()); }
                   destroyApp(false);
                   notifyDestroyed();
         public void run()
              try
                   disp.setCurrent(textForm);
                   ssc = (ServerSocketConnection)Connector.open("socket://:2000");
                   while(true)               
                        sc = (SocketConnection) ssc.acceptAndOpen();     
                        connection.addElement(sc);                                                  
                        out = new PrintStream(sc.openOutputStream());
                        textForm.append(sc.getAddress() + " has connected\n");
                        ServerToClient stc = new ServerToClient(sc);
                        stc.start();
              catch(IOException err) { System.out.println("IOException error: " + err.getMessage()); }
              catch(NullPointerException err) { System.out.println("NullPointerException error: " + err.getMessage()); }
         class ServerToClient extends Thread
              String message;
              InputStream in;
              SocketConnection sc;
              ServerToClient(SocketConnection sc)
                   this.sc = sc;
              public void run()
                   try
                        in = sc.openInputStream();
                        int ch;
                        while((ch = in.read())!= -1)                         
                             System.out.print((char)ch);
                             char cha = (char)ch;                              
                             String str = String.valueOf(cha);                    
                             out.print(str);
                             //broadcast(str);
                             textForm.append(str);                              
                        in.close();
                        //out.close();
                           sc.close();
                   catch(IOException err) { System.out.println("IOException error: " + err.getMessage()); }
    }

  • Force user to connect to specific Persistent Chat server

    We plan to have 2 persistent chat servers in a single pool that will span 2 sites.
    1 Persistent Chat server in Site A
    1 Persistent Chat server in Site B
    Is there a way to force users in Site A to connect to the Persistent Chat server in Site A and for users in Site B to connect to the Site B Persistent Chat server?

    That is possible.
    For example, you have on DNS server DC01 in site A, and you only have a DNS A record point to the IP address of persistent chat server in site A, then you use DC01 as the DNS server for users in site A.
    You have on DNS server DC02 in site B, and you only have a DNS A record point to the IP address of persistent chat server in site B, then you use DC02 as the DNS server for users in site B.
    But it is not recommended. If one persistent server is down, users in one site won’t have group chat feature.
    Lisa Zheng
    TechNet Community Support

  • [Help] To prevent timeout error of browser in clinet with servlet in server

    Hi all,
    If a browser (for example, Internet Explorer) do not get any response from a server for more than sometime (in case of IE, default is 5 min), it will stop waiting and return some timeout error message.
    But I have a servlet, which has a really long-time(at least 10 min) job to do before it could send a response to the browser. So, before the browser in client can get the result, it stops waiting.
    I know I can change the time-out setting of browser in client machines, but there are hundred of thousands.
    So, what I am asking is if it is possible to do it with servlet in server, and how?
    (for example, send something to the client every few minutes, but I do not know how to do it .)
    thanks a lot!

    What you would have to do is set up some sort of 'Buffer' servlet.
    It starts the job in the background, and then returns a page saying job started - client does not time out.
    You would have to start it in a seperate process - probably a new Thread.
    The client would then have to send back requests asking - is it finished yet?
    While the job is not finished the buffer servlet returns a "not yet" message.
    On completion, the job can be sent back to the client.
    Couple of pointers:
    It may be easier to have the background process generate the result to file - then your buffer servlet can just pick up the file when it is completed.
    To get your page to refresh multiple times, you can use javascript: window.setTimeout("[reload page]");
    Good luck,
    evnafets

  • Multiple client chat server

    Thanks to the help I got from the good people of this forum today I modified the chat server program which I am making and now it is working a bit better. Right now it can accept several (up to 8) clients and store their open sockets in a SocketCollection list which can later be accessed so that messages get sent to all of them. Problem is that when I send a message, it is displayed instantaneously on the client that sent that message (my machine), but is displayed only after the other clients press enter on the other clients' machines (for testing purposes it was the same machine, different port opened for communication with server which is also on the same machine). To clarify that - all clients and server are the same machine (that shouldn't be a problem, right?). Code for printing incoming data for client program is below:
    while ((fromServer = in.readLine()) != null) {
                if (fromServer!=null){
                       System.out.println(fromServer);
                       System.out.println("print on client screen msg received from server");
                fromUser = stdIn.readLine();
                if (fromUser != null) {
              System.out.println("Client: " + fromUser);
              out.println(fromUser);
    }Code to deliver the message to all clients from the server application is below as well:
    while ((inputLine = in.readLine()) != null) {
                     PrintWriter multiOut;
                   for (int x=0; x<8; x++){
                         System.out.println("INSIDE MULTI-TELL FOR LOOP");
                         if (socketCollection[x]!=null){
                               Socket c=socketCollection[x];
                               try{
                                   System.out.println("tried to send to all\nSocket c = " + c);
                                   out=new PrintWriter(c.getOutputStream(), true);
                                       out.println(c.getInetAddress() + inputLine);
                                catch(IOException ioe){}
    }In the server's DOS window I can clearly see that it enters to display the message to multiple clients and it should send it. The sockets are all different and they point to different ports on different clients' machines. Maybe the problem is just in the client program's code. If you could help me out, it will be greatly appreciated. Thank you very much.

    The sockets get created one by one when each client connects. Afterwards when the thread is made, that socket gets copied into the SocketCollection array which can afterwards be accessed in order for the server to distribute the message to all its connected clients.
    The for loop in the second code example where it takes SocketCollection[x] and gets its outputStream and all that is where it prints the message and sends it to each client (sends it but it is not displayed on the client side until the client sends a message to the server again). My question is how to make it so the client does not have to send a message in order to see the server message (message to all clients) that was sent before.

  • Developing a chat server ...

    Dear all
    I am planning to develop a chat server to be used locally in my company. I want the members of this server to be able to connect to thier msn and yahoo messenger contacts.
    Is it possible? How can I do it? detailed explaination, please.
    even give any useful links...
    Best Regards

    do you mean some program like JBuddy Messenger,
    you can try this, it is a good example.
    currently it supports AIM, MSN, ICQ, Yahoo and JBuddy protocol.

  • Best thread method for a chat server

    What would be the best way to thread a chat server in Java? I understand threads, but I'm new to java. I'm just looking for links to the appropriate classes not code. I already have the send/receive methods planed, but I'm interested in the best ways to pool the clients once connected.

    class: Thread
    interface: Runnable
    The two items above are what you need.

  • Chat Server Help

    I'm developing a chat server and I am handling it with threads. I developed a executable class to handle all and I'm putting all the users in two Hashtables. There are two kinds of users. I need to know how many users do you gurus believe it can support? and how could I make it better. Thanks
    Ivan

    the way you do it is okay and the size of the hashtables is just limited by the space the jvm has and the kind of keys you are using.
    regards

  • Need some help on JAVA CHAT SERVER

    i need some info about java chat server. Please any one who have developed give me the details about the logic and process flow.

    Have you read any of these?
    http://search.java.sun.com/search/java/index.jsp?qp=&nh=10&qt=%2B%22chat+server%22&col=javaforums

  • Ask about chat server

    i learning today to wrote a server and client
    and i wrote
    echo server
    and time server...
    i wanna know how i build a chat server
    the problem is
    when someone wrote something
    how every clients see the message
    i think about main panel
    but i dont know how..
    tnxxxx

    amosexy wrote:
    no
    i just learning today how to open connection
    and write some server
    and i wanna know the idea behind the chat
    Had you paid attention and done your own homework on those previous assignments you'd have known how to do that already.

Maybe you are looking for