DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2

Thread: Java socket

  1. #1
    Join Date
    Aug 2002
    Posts
    2

    Java socket

    I am trying to open a socket and send a
    query to a remote comp. It connects allright, but does not
    respond to the query, not even with an error message - that's
    the problem.

    just fyi - the ultimate goal of this program is to find mashines
    within given IP range and read their parameters (hostname, mac
    address, etc.)

    Thanks a bunch!
    alex


    try {
    input = new BufferedReader(new
    InputStreamReader(System.in));
    OutputStream out = socket.getOutputStream();

    out.write (45);
    System.out.println ("start reading");
    BufferedReader din =
    new BufferedReader(new InputStreamReader
    (socket.getInputStream()));
    System.out.println ("done creating object");
    response = din.readLine();
    System.out.println ("done reading");

    System.out.print (response);
    socket.close();
    //}
    }
    catch (IOException e) {
    System.out.println(e);
    }

  2. #2
    Join Date
    Jul 2002
    Posts
    60

    Question tried the URL class??

    have you tried the URL connections?
    It will open a connection, then you'll have to request the rest once it's opened. it takes a full http://www.blah.com/
    url argument at the command line
    ----------------------------------
    import java.io.*;
    import java.net.*;

    public class Url {
    public static void main(String args[]) {
    boolean conn=true;
    for (int i = 0; i <args.length; i++){
    try{
    URL u = new URL(args[i]);

    try{ URLConnection uc = u.openConnection();
    InputStream in = uc.getInputStream( );
    } catch (IOException e) {
    conn=false;
    }

    }catch (MalformedURLException e) {
    conn=false;
    } //end first try
    } //end for

    if (conn)
    System.out.println(conn);
    else
    System.out.println(conn);
    }
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links