Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Communications between two or more machines

Thread view: 
Matthew - 21 Jul 2006 04:01 GMT
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.
Martin Gregorie - 22 Jul 2006 11:37 GMT
> 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
[quoted text clipped - 51 lines]
> Once, I erased the portion bet HERE but the apps in the webserver did
> not work. Please do reply. thanks.

Try connecting before sending the message to the server.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.