Results 1 to 1 of 1
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default Connecting to a Web server

    This Java tip shows how to connect to a web server.

    Java Code:
    import java.net.InetAddress;
    import java.net.Socket;
    
    public class WebPing {
      public static void main(String[] args) {
        try {
          InetAddress addr;
          Socket sock = new Socket("www.java-tips.org.com", 80);
          addr = sock.getInetAddress();
          System.out.println("Connected to " + addr);
          sock.close();
        } catch (java.io.IOException e) {
          System.out.println("Can't connect to " + args[0]);
          System.out.println(e);
        }
      }
    }
    Last edited by Java Tip; 04-07-2008 at 08:02 PM.

Similar Threads

  1. connecting to a database
    By mxb7642 in forum JDBC
    Replies: 5
    Last Post: 09-08-2009, 08:39 AM
  2. Connecting to a database
    By peiceonly in forum New To Java
    Replies: 2
    Last Post: 04-06-2008, 02:28 PM
  3. Java connecting to sql server 2005
    By pelegk2 in forum JDBC
    Replies: 0
    Last Post: 04-05-2008, 09:17 PM
  4. Connecting to DB from Applet
    By ibanez270dx in forum New To Java
    Replies: 1
    Last Post: 11-13-2007, 11:51 PM
  5. Who will know like connecting from Websphere
    By Albert in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 03:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •