Communications between two or more machines

Discussion in 'Java' started by Matthew, Jul 21, 2006.

  1. Matthew

    Matthew Guest

    Hello, I have a problem here. I have 2 machines. 1 is a webserver and
    the other is the client machine. The client machine calls the webserver
    to execute a particular application. Now the problem is my client
    machine (using Java's HTTP.... classes) keeps on waiting until the
    process in the web server finish executing. The code below calls the
    webserver:

    public void caller()
    {

    String host = "www.google.com";
    String content = "hello...";

    try
    {
    URL url = new URL(host);

    URLConnection uc = url.openConnection ();

    if (!(uc instanceof HttpURLConnection))
    {
    System.err.println ("Wrong connection type");
    return;
    }

    uc.setDoOutput (true);
    uc.setUseCaches (true);
    HttpURLConnection hc = (HttpURLConnection) uc;
    hc.setRequestMethod ("POST");
    OutputStream os = uc.getOutputStream ();
    DataOutputStream dos = new DataOutputStream (os);
    dos.writeBytes (content);

    dos.flush ();
    dos.close ();

    uc.connect();

    // -- HERE (Get the reply of the webserver)
    InputStream is = uc.getInputStream ();
    int ch;
    while ((ch = is.read ()) != -1)
    System.out.print ((char) ch);

    is.close ();
    // -- HERE (End)
    }
    catch (Exception e)
    {
    System.out.println(ipAddr+" "+e.getMessage());
    }
    }

    Once, I erased the portion bet HERE but the apps in the webserver did
    not work. Please do reply. thanks.
     
    Matthew, Jul 21, 2006
    #1
    1. Advertisements

  2. Try connecting before sending the message to the server.
     
    Martin Gregorie, Jul 22, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.