集册 Java实例教程 创建客户端套接字

创建客户端套接字

欢马劈雪     最近更新时间:2020-01-02 10:19:05

452
创建客户端套接字



import java.io.IOException;//来自 时 代 J a v a - N o w J a v a . c o m

import java.net.InetAddress;

import java.net.Socket;

import java.net.UnknownHostException;


public class Main {

  public static void main(String[] args) {

    // Create a socket without a timeout

    try {

      InetAddress addr = InetAddress.getByName("java.sun.com");

      int port = 80;


      // This constructor will block until the connection succeeds

      Socket socket = new Socket(addr, port);

    } 
展开阅读全文