Java Code Examples for org.apache.mina.transport.socket.nio.NioSocketConnector#setConnectTimeout()

The following examples show how to use org.apache.mina.transport.socket.nio.NioSocketConnector#setConnectTimeout() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MinaTimeClient.java    From javabase with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	// 创建客户端连接器.
	NioSocketConnector connector = new NioSocketConnector();
	connector.getFilterChain().addLast("logger", new LoggingFilter());
	connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8")))); // 设置编码过滤器
	connector.setConnectTimeout(30);
	connector.setHandler(new TimeClientHandler());// 设置事件处理器
	ConnectFuture cf = connector.connect(new InetSocketAddress("127.0.0.1", 9123));// 建立连接
	cf.awaitUninterruptibly();// 等待连接创建完成
	cf.getSession().write("hello");// 发送消息
	cf.getSession().write("quit");// 发送消息
	cf.getSession().getCloseFuture().awaitUninterruptibly();// 等待连接断开
	connector.dispose();
}
 
Example 2
Source File: WebSocketServerTest.java    From red5-websocket with Apache License 2.0 5 votes vote down vote up
public WSClient(String host, int port) {
    this.host = host;
    this.port = port;
    connector = new NioSocketConnector();
    connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new WebSocketCodecFactory()));
    connector.setHandler(this);
    SocketSessionConfig sessionConf = connector.getSessionConfig();
    sessionConf.setReuseAddress(true);
    connector.setConnectTimeout(3);
}
 
Example 3
Source File: WebSocketServerTest.java    From red5-websocket with Apache License 2.0 5 votes vote down vote up
public WSClient(String host, int port, int cookieLength) {
    this.cookie = RandomStringUtils.randomAscii(cookieLength);
    log.debug("Cookie length: {}", cookie.length());
    this.host = host;
    this.port = port;
    connector = new NioSocketConnector();
    connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new WebSocketCodecFactory()));
    connector.setHandler(this);
    SocketSessionConfig sessionConf = connector.getSessionConfig();
    sessionConf.setReuseAddress(true);
    connector.setConnectTimeout(3);
}