← 返回首页
Socket (Java SE 26 & JDK 26)
JavaScript is disabled on your browser.
Contents  
  1. Description
  2. Constructor Summary
  3. Method Summary
  4. Constructor Details
    1. Socket()
    2. Socket(Proxy)
    3. Socket(SocketImpl)
    4. Socket(String, int)
    5. Socket(InetAddress, int)
    6. Socket(String, int, InetAddress, int)
    7. Socket(InetAddress, int, InetAddress, int)
    8. Socket(String, int, boolean)
    9. Socket(InetAddress, int, boolean)
  5. Method Details
    1. connect(SocketAddress)
    2. connect(SocketAddress, int)
    3. bind(SocketAddress)
    4. getInetAddress()
    5. getLocalAddress()
    6. getPort()
    7. getLocalPort()
    8. getRemoteSocketAddress()
    9. getLocalSocketAddress()
    10. getChannel()
    11. getInputStream()
    12. getOutputStream()
    13. setTcpNoDelay(boolean)
    14. getTcpNoDelay()
    15. setSoLinger(boolean, int)
    16. getSoLinger()
    17. sendUrgentData(int)
    18. setOOBInline(boolean)
    19. getOOBInline()
    20. setSoTimeout(int)
    21. getSoTimeout()
    22. setSendBufferSize(int)
    23. getSendBufferSize()
    24. setReceiveBufferSize(int)
    25. getReceiveBufferSize()
    26. setKeepAlive(boolean)
    27. getKeepAlive()
    28. setTrafficClass(int)
    29. getTrafficClass()
    30. setReuseAddress(boolean)
    31. getReuseAddress()
    32. close()
    33. shutdownInput()
    34. shutdownOutput()
    35. toString()
    36. isConnected()
    37. isBound()
    38. isClosed()
    39. isInputShutdown()
    40. isOutputShutdown()
    41. setSocketImplFactory(SocketImplFactory)
    42. setPerformancePreferences(int, int, int)
    43. setOption(SocketOption, T)
    44. getOption(SocketOption)
    45. supportedOptions()
Hide sidebar  Show sidebar

Class Socket

java.lang.Object
java.net.Socket
All Implemented Interfaces: Closeable, AutoCloseable Direct Known Subclasses: SSLSocket
public class Socket extends Object implements Closeable
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines.

The actual work of the socket is performed by an instance of the SocketImpl class.

The Socket class defines convenience methods to set and get several socket options. This class also defines the setOption and getOption methods to set and query socket options. A Socket support the following options:

Socket options Option Name Description SO_SNDBUFSO_RCVBUFSO_KEEPALIVESO_REUSEADDRSO_LINGERTCP_NODELAY
The size of the socket send buffer
The size of the socket receive buffer
Keep connection alive
Re-use address
Linger on close if data is present (when configured in blocking mode only)
Disable the Nagle algorithm
Additional (implementation specific) options may also be supported.

Since: 1.0 See Also:

Scripting on this page tracks web page traffic, but does not change the content in any way.