Uses of Class java.net.Socket (Java Platform SE 8 )
Date: 2026-04-17

## Uses of Class
java.net.Socket

- Packages that use Socket
  Package | Description
  --- | ---
  java.net | Provides the classes for implementing networking applications.
  java.nio.channels | Defines channels, which represent connections to entities that are capable of performing I/O operations, such as files and sockets; defines selectors, for multiplexed, non-blocking I/O operations.
  java.rmi.server | Provides classes and interfaces for supporting the server side of RMI.
  javax.net | Provides classes for networking applications.
  javax.net.ssl | Provides classes for the secure socket package.
  javax.rmi.ssl | Provides implementations of `RMIClientSocketFactory` and `RMIServerSocketFactory` over the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocols.

- - ### Uses of Socket in java.net

    Methods in java.net that return Socket
    Modifier and Type | Method and Description
    --- | ---
    `Socket` | ServerSocket.`accept()` Listens for a connection to be made to this socket and accepts it.

    Methods in java.net with parameters of type Socket
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | ServerSocket.`implAccept(Socket s)` Subclasses of ServerSocket use this method to override accept() to return their own subclass of socket.

  - ### Uses of Socket in java.nio.channels

    Methods in java.nio.channels that return Socket
    Modifier and Type | Method and Description
    --- | ---
    `abstract Socket` | SocketChannel.`socket()` Retrieves a socket associated with this channel.

  - ### Uses of Socket in java.rmi.server

    Methods in java.rmi.server that return Socket
    Modifier and Type | Method and Description
    --- | ---
    `Socket` | RMIClientSocketFactory.`createSocket(String host, int port)` Create a client socket connected to the specified host and port.
    `abstract Socket` | RMISocketFactory.`createSocket(String host, int port)` Creates a client socket connected to the specified host and port.

  - ### Uses of Socket in javax.net

    Methods in javax.net that return Socket
    Modifier and Type | Method and Description
    --- | ---
    `Socket` | SocketFactory.`createSocket()` Creates an unconnected socket.
    `abstract Socket` | SocketFactory.`createSocket(InetAddress host, int port)` Creates a socket and connects it to the specified port number at the specified address.
    `abstract Socket` | SocketFactory.`createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)` Creates a socket and connect it to the specified remote address on the specified remote port.
    `abstract Socket` | SocketFactory.`createSocket(String host, int port)` Creates a socket and connects it to the specified remote host at the specified remote port.
    `abstract Socket` | SocketFactory.`createSocket(String host, int port, InetAddress localHost, int localPort)` Creates a socket and connects it to the specified remote host on the specified remote port.

  - ### Uses of Socket in javax.net.ssl

    Subclasses of Socket in javax.net.ssl
    Modifier and Type | Class and Description
    --- | ---
    `class` | `SSLSocket` This class extends `Socket`s and provides secure socket using protocols such as the "Secure Sockets Layer" (SSL) or IETF "Transport Layer Security" (TLS) protocols.

    Methods in javax.net.ssl that return Socket
    Modifier and Type | Method and Description
    --- | ---
    `Socket` | SSLSocketFactory.`createSocket(Socket s, InputStream consumed, boolean autoClose)` Creates a server mode `Socket` layered over an existing connected socket, and is able to read data which has already been consumed/removed from the `Socket`'s underlying `InputStream`.
    `abstract Socket` | SSLSocketFactory.`createSocket(Socket s, String host, int port, boolean autoClose)` Returns a socket layered over an existing socket connected to the named host, at the given port.

    Methods in javax.net.ssl with parameters of type Socket
    Modifier and Type | Method and Description
    --- | ---
    `abstract void` | X509ExtendedTrustManager.`checkClientTrusted(X509Certificate[] chain, String authType, Socket socket)` Given the partial or complete certificate chain provided by the peer, build and validate the certificate path based on the authentication type and ssl parameters.
    `abstract void` | X509ExtendedTrustManager.`checkServerTrusted(X509Certificate[] chain, String authType, Socket socket)` Given the partial or complete certificate chain provided by the peer, build and validate the certificate path based on the authentication type and ssl parameters.
    `String` | X509KeyManager.`chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket)` Choose an alias to authenticate the client side of a secure socket given the public key type and the list of certificate issuer authorities recognized by the peer (if any).
    `String` | X509KeyManager.`chooseServerAlias(String keyType, Principal[] issuers, Socket socket)` Choose an alias to authenticate the server side of a secure socket given the public key type and the list of certificate issuer authorities recognized by the peer (if any).
    `Socket` | SSLSocketFactory.`createSocket(Socket s, InputStream consumed, boolean autoClose)` Creates a server mode `Socket` layered over an existing connected socket, and is able to read data which has already been consumed/removed from the `Socket`'s underlying `InputStream`.
    `abstract Socket` | SSLSocketFactory.`createSocket(Socket s, String host, int port, boolean autoClose)` Returns a socket layered over an existing socket connected to the named host, at the given port.

  - ### Uses of Socket in javax.rmi.ssl

    Methods in javax.rmi.ssl that return Socket
    Modifier and Type | Method and Description
    --- | ---
    `Socket` | SslRMIClientSocketFactory.`createSocket(String host, int port)` Creates an SSL socket.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.