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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
2017-08-29 SpringBoot(二) :web综合开发