Socket Info : Socket « Network « Java Tutorial






import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;

public class MainClass {

  public static void main(String[] args) {

    try {
      Socket theSocket = new Socket("127.0.0.1", 80);
      System.out.println("Connected to " + theSocket.getInetAddress() + " on port "
          + theSocket.getPort() + " from port " + theSocket.getLocalPort() + " of "
          + theSocket.getLocalAddress());
    } catch (UnknownHostException ex) {
      System.err.println(ex);
    } catch (SocketException ex) {
      System.err.println(ex);
    } catch (IOException ex) {
      System.err.println(ex);
    }

  }

}








19.9.Socket
19.9.1.java.net.Socket
19.9.2.Create a socket
19.9.3.Create Socket by IP address and port number
19.9.4.Display Socket InetAddress, Port, LocalPort and Local address
19.9.5.Socket Info
19.9.6.Get InputStream and OutputStream from Socket
19.9.7.Read float number from a Socket
19.9.8.Read Object from Socket
19.9.9.A Thin SMTP Client
19.9.10.Get internet address from connected socket client
19.9.11.Transfer a file via Socket
19.9.12.Cipher Socket