Connect with a Web server : Web Server Client « Network Protocol « Java






Connect with a Web server

Connect with a Web server
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.java2s.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);
    }
  }
}
           
       








Related examples in the same category

1.Java HTTP/HTTPS Server Based on new io
2.Reading URLs Protected with HTTP Authentication
3.Reading Web Pages with StreamsReading Web Pages with Streams
4.Reading Web Pages, with Socket ChannelsReading Web Pages, with Socket Channels
5.Reading Web Pages with Nonblocking ChannelsReading Web Pages with Nonblocking Channels
6.A Simple Web ServerA Simple Web Server
7.Web server
8.Save binary file from web