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