20230627 java.net.Socket

介绍

  • java.net.Socket
  • public class Socket implements java.io.Closeable
  • 套接字( Socket )是网络软件中的一个抽象概念,负责启动该程序内部和外部之间的通信

API

构造器

  • Socket()
  • Socket(Proxy proxy)
  • Socket(String host, int port) throws UnknownHostException, IOException
  • Socket(InetAddress address, int port) throws IOException
  • Socket(String host, int port, InetAddress localAddr, int localPort) throws IOException
  • Socket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException
    • 创建一个还未被连接的套接字
    • UnknownHostException 是 IOException 的子类

public

  • connect

    • void connect(SocketAddress endpoint) throws IOException
    • void connect(SocketAddress endpoint, int timeout) throws IOException
    • 将套接字连接到远程主机
  • bind

    • void bind(SocketAddress bindpoint) throws IOException
    • 将套接字绑定到本地地址
    • 可选,如果没有显式调用,Java会自动为Socket分配一个未使用的端口,并使用该端口和localhost地址进行绑定
  • close

  • isConnected

  • isBound

  • isClosed

  • setSoTimeout, getSoTimeout

    • 设置该套接字上读请求的阻塞时间
  • getInetAddress

  • getLocalAddress

  • getPort

  • getLocalPort

  • getRemoteSocketAddress

  • getLocalSocketAddress

  • getChannel

  • setTcpNoDelay, getTcpNoDelay

  • setSoLinger, getSoLinger

  • sendUrgentData

  • setOOBInline, getOOBInline

  • setSendBufferSize, getSendBufferSize

  • setReceiveBufferSize, getReceiveBufferSize

  • setKeepAlive, getKeepAlive

  • setTrafficClass, getTrafficClass

  • setReuseAddress, getReuseAddress

  • setSocketImplFactory

  • setPerformancePreferences

  • setOption, getOption

  • supportedOptions

输入输出流

  • getInputStream

  • getOutputStream

  • shutdownInput

    • 将输出流设为 “流结束”
  • shutdownOutput

    • 将输入流设为 “流结束”
  • isInputShutdown

  • isOutputShutdown

posted @   流星<。)#)))≦  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
历史上的今天:
2017-08-29 SpringBoot(二) :web综合开发
点击右上角即可分享
微信分享提示