当前位置: 首页>>代码示例>>Java>>正文


Java SocketConnector.setConnectTimeoutMillis方法代码示例

本文整理汇总了Java中org.apache.mina.transport.socket.SocketConnector.setConnectTimeoutMillis方法的典型用法代码示例。如果您正苦于以下问题:Java SocketConnector.setConnectTimeoutMillis方法的具体用法?Java SocketConnector.setConnectTimeoutMillis怎么用?Java SocketConnector.setConnectTimeoutMillis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.transport.socket.SocketConnector的用法示例。


在下文中一共展示了SocketConnector.setConnectTimeoutMillis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.mina.transport.socket.SocketConnector; //导入方法依赖的package包/类
public static void main(String[] args) throws Throwable
{
	IoBuffer.setUseDirectBuffer(false);
	IoBuffer.setAllocator(new SimpleBufferAllocator());

	SocketConnector connector =
		new NioSocketConnector(Runtime.getRuntime().availableProcessors() + 1);

	// Configure the service.
	connector.setConnectTimeoutMillis(CONNECT_TIMEOUT);

	connector.getFilterChain().addLast("threadPool", new ExecutorFilter(Executors.newFixedThreadPool(MAX_THREADS)));
	connector.getFilterChain().addLast("codec",
										new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
	connector.getFilterChain().addLast("logger", new LoggingFilter());

	SMTPSessionHandler handler = new SMTPSessionHandler("localhost");
	connector.setHandler(handler);
	while (true)
	{
		try
		{
			for (int i = 0; i < 10; i++)
				connector.connect(new InetSocketAddress(HOSTNAME, PORT));
			Thread.sleep(100);
		}
		catch (RuntimeIoException e)
		{
			System.err.println("Failed to connect.");
			e.printStackTrace();
			Thread.sleep(1000);
		}
	}
}
 
开发者ID:edeoliveira,项目名称:MailsterSMTP,代码行数:35,代码来源:SMTPClient.java

示例2: main

import org.apache.mina.transport.socket.SocketConnector; //导入方法依赖的package包/类
public static void main(String[] args) throws InvalidProtocolBufferException {
		SocketConnector connector = new NioSocketConnector();
		connector.setConnectTimeoutMillis(30 * 1000);
		DefaultProtocolCodecFactory defaultProtocolCodecFactory=new DefaultProtocolCodecFactory();
		defaultProtocolCodecFactory.setDecoder(new ProtocolBufferDecoder());
		defaultProtocolCodecFactory.setEncoder(new ProtocolBufferEncoder());
		connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(defaultProtocolCodecFactory));
		connector.setHandler(new Client());
		ConnectFuture future = connector.connect((SocketAddress)SpringContext.getBean("gameServerBindAddress"));
		future.awaitUninterruptibly();
		
		
		
		
		IoSession session=future.getSession();
		Person persion=Test.Person.newBuilder().setId(1).setName("侧方dfdfdfd").build();
		
//		IResponseMessage msg=new ResponseMessage(1, 1,persion);
//		client.write(msg);
		
		/**
		 * <body>
		 * <pre>
		 *      BEFORE ENCODE 			 AFTER ENCODE 
		 * +-----------+-------------+------------+    	    +----------+               
		 * | actionID  | datalength  |  Data 	  | ----->  |    Data  |
		 * |	short  | short       | bytes(300) |    	    |   (bytes)|                
		 * +-----------+-------------+------------+    	    +----------+    
		 * </pre>           
		 * </body>                     
		 */
			short ioSize = (short) persion.toByteArray().length;
			
			IoBuffer buffer = IoBuffer.allocate(ioSize + 8).setAutoExpand(true);
			buffer.putShort((short)1);
			buffer.putShort(ioSize);
			buffer.put( persion.toByteArray());
			buffer.flip();
//			session.write(buffer);
			 persion=Test.Person.newBuilder().mergeFrom( persion.toByteArray()).build();
			
			System.out.println( TextFormat.printToUnicodeString(persion));

	}
 
开发者ID:myking520,项目名称:gamefm,代码行数:45,代码来源:Client.java


注:本文中的org.apache.mina.transport.socket.SocketConnector.setConnectTimeoutMillis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。