20230627 java.net.ServerSocket

发布时间 2023-08-29 17:08:03作者: 流星<。)#)))≦

介绍

  • java.net.ServerSocket
  • public class ServerSocket implements java.io.Closeable
  • 服务器套接字
  • ServerSocket 类用于建立套接字,accept 用于告诉程序不停地等待,直到有客户端连接到这个端口。一旦有人通过网络发送了正确的连接请求,并以此连接到了端口上,该方法就会返回一个表示连接已经建立的 Socket 对象。你可以使用这个对象来得到输入流和输出流

API

构造器

  • ServerSocket() throws IOException
  • ServerSocket(int port) throws IOException
  • ServerSocket(int port, int backlog) throws IOException
  • ServerSocket(int port, int backlog, InetAddress bindAddr) throws IOException

public

  • accept

    • Socket accept() throws IOException
    • 等待连接。该方法阻塞当前线程直到建立连接为止。该方法返回一个Socket 对象,程序可以通过这个对象与连接中的客户端进行通信
  • bind

  • close

  • isBound

  • isClosed

  • getInetAddress

  • getLocalPort

  • getLocalSocketAddress

  • getChannel

  • setSoTimeout, getSoTimeout

  • setReuseAddress, getReuseAddress

  • setSocketFactory

  • setReceiveBufferSize, getReceiveBufferSize

  • setPerformancePreferences

  • setOption, getOption

  • supportedOptions