public class TcpSocket extends SocketContext<SocketChannel,TcpSession>
ACCEPT_THREAD_SIZE, ASYNC_RECIVE, ASYNC_SEND, CHECK_TIMEOUT, COMMON_ACCEPT_EVENT_RUNNER_GROUP, COMMON_IO_EVENT_RUNNER_GROUP, connectModel, connectType, filterChain, handler, host, idleInterval, IO_THREAD_SIZE, isSynchronous, lastReadTime, messageSplitter, port, readBufferSize, readTimeout, reciveFilterChain, SELECT_INTERVAL, sendBufferSize, sendFilterChain, sendTimeout, sslManager| Constructor and Description |
|---|
TcpSocket(SocketContext parentSocketContext,
SocketChannel socketChannel)
构造函数
|
TcpSocket(String host,
int port,
int readTimeout)
socket 连接
默认不会出发空闲事件, 默认发超时时间: 1s
|
TcpSocket(String host,
int port,
int readTimeout,
int idleInterval)
socket 连接
默认发超时时间: 1s
|
TcpSocket(String host,
int port,
int readTimeout,
int sendTimeout,
int idleInterval)
socket 连接
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
acceptStart()
用于针对 Accept 进来的 Socket 连接的启动
|
boolean |
close()
关闭连接
|
TcpSession |
getSession()
获取 Session 对象
|
boolean |
isConnected()
上下文连接是否连接
|
boolean |
isOpen()
上下文连接是否打开
|
void |
setIdleInterval(int idleInterval)
设置空闲事件时间
|
<T> void |
setOption(SocketOption<T> name,
T value)
设置 Socket 的 Option 选项
|
SocketChannel |
socketChannel()
获取 SocketChannel 对象
|
void |
start()
启动同步的上下文连接,
阻塞方法
|
Object |
syncRead()
同步读取消息
|
void |
syncSend(Object obj)
同步发送消息
|
void |
syncStart()
启动同步的上下文连接
非阻塞方法
|
bindToSocketSelector, copyFrom, createEventRunnerGroup, filterChain, getAcceptEventRunnerGroup, getCommonAcceptEventRunnerGroup, getCommonIoEventRunnerGroup, getConnectModel, getConnectType, getHost, getIdleInterval, getIoEventRunnerGroup, getLastReadTime, getPort, getReadBufferSize, getReadTimeout, getReciveFilterChain, getSendBufferSize, getSendFilterChain, getSendTimeout, getSSLManager, gracefulShutdown, handler, handler, initSSL, isRegister, isTimeOut, messageSplitter, messageSplitter, setAcceptEventRunnerGroup, setIoEventRunnerGroup, setReadBufferSize, setRegister, setSendBufferSize, setSSLManager, updateLastTime, waitConnectgetPoolObjectId, setPoolObjectIdpublic TcpSocket(String host, int port, int readTimeout) throws IOException
host - 监听地址port - 监听端口readTimeout - 超时时间, 单位: 毫秒IOException - IO异常public TcpSocket(String host, int port, int readTimeout, int idleInterval) throws IOException
host - 监听地址port - 监听端口idleInterval - 空闲事件触发时间, 单位: 秒readTimeout - 超时时间, 单位: 毫秒IOException - IO异常public TcpSocket(String host, int port, int readTimeout, int sendTimeout, int idleInterval) throws IOException
host - 监听地址port - 监听端口idleInterval - 空闲事件触发时间, 单位: 秒readTimeout - 超时时间, 单位: 毫秒sendTimeout - 发超时时间, 单位: 毫秒IOException - IO异常public TcpSocket(SocketContext parentSocketContext, SocketChannel socketChannel)
parentSocketContext - 父 SocketChannel 对象socketChannel - SocketChannel 对象public void setIdleInterval(int idleInterval)
SocketContextsetIdleInterval in class SocketContext<SocketChannel,TcpSession>idleInterval - 空闲事件时间, 单位:秒public <T> void setOption(SocketOption<T> name, T value) throws IOException
setOption in class SocketContext<SocketChannel,TcpSession>T - 范型name - SocketOption类型的枚举, 参照:SocketChannel.setOption的说明value - SocketOption参数IOException - IO异常public SocketChannel socketChannel()
socketChannel in class SocketContext<SocketChannel,TcpSession>public TcpSession getSession()
getSession in class SocketContext<SocketChannel,TcpSession>public void start()
throws IOException
start in class SocketContext<SocketChannel,TcpSession>IOException - IO 异常public void syncStart()
throws IOException
syncStart in class SocketContext<SocketChannel,TcpSession>IOException - IO异常protected void acceptStart()
throws IOException
SocketContextacceptStart in class SocketContext<SocketChannel,TcpSession>IOException - IO异常public boolean isOpen()
SocketContextisOpen in class SocketContext<SocketChannel,TcpSession>public boolean isConnected()
SocketContextisConnected in class SocketContext<SocketChannel,TcpSession>public Object syncRead() throws ReadMessageException
ReadMessageException - 读取消息异常public void syncSend(Object obj) throws SendMessageException
obj - 要发送的对象SendMessageException - 消息发送异常public boolean close()
SocketContextclose in class SocketContext<SocketChannel,TcpSession>Copyright © 2020 Voovan. All rights reserved.