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


Java IoSession.write方法代码示例

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


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

示例1: main

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception{
	int port=9527;
	
	final IoAcceptor acceptor=new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
               							   Executors.newCachedThreadPool());
	acceptor.getFilterChain().addLast("stringserialize", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	IoHandler handler=new IoHandlerAdapter(){

		public void messageReceived(IoSession session, Object message)
				throws Exception {
			if("quit".equalsIgnoreCase(message.toString())){
				acceptor.unbindAll();
				System.out.println("Server has been shutdown!");
				System.exit(0);
			}
			System.out.println("Message from client: "+message);
			session.write("Server response��"+message);
		}
		
	};
	acceptor.bind(new InetSocketAddress(port), handler);
	System.out.println("Server listen on port: "+port);
}
 
开发者ID:java-scott,项目名称:java-project,代码行数:24,代码来源:Server.java

示例2: sessionOpened

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(final IoSession session) throws Exception {
	
    // Start of IP checking
    final String address = session.getRemoteAddress().toString().split(":")[0];
    final short port = Short.parseShort(session.getServiceAddress().toString().split(":")[1]);
    
    if (LoginServer.isShutdown()) {
        session.close();
        return;
    }

    // IV used to decrypt packets from client.
    final byte ivRecv[] = new byte[]{(byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255)};
    
    // IV used to encrypt packets for client.
    final byte ivSend[] = new byte[]{(byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255), (byte) Randomizer.nextInt(255)};

    MapleClient client = new MapleClient(
            new MapleAESOFB(skey, ivSend, (short) (0xFFFF - ServerConstants.MAPLE_VERSION)),
            new MapleAESOFB(skey, ivRecv, ServerConstants.MAPLE_VERSION), session);
    client.setChannel(-1);

    MaplePacketDecoder.DecoderState decoderState = new MaplePacketDecoder.DecoderState();
    session.setAttribute(MaplePacketDecoder.DECODER_STATE_KEY, decoderState);
    
    session.write(LoginPacket.getHello(ServerConstants.MAPLE_VERSION, ivSend, ivRecv));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
    session.setIdleTime(IdleStatus.READER_IDLE, 60);
    session.setIdleTime(IdleStatus.WRITER_IDLE, 60);

    System.out.println("Connection Established " + address + ":"+port);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:34,代码来源:MapleServerHandler.java

示例3: sendErrorResponse

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
private void sendErrorResponse(final IoSession session, final RequestWrapper request) {
  ResponseWrapper responseWrapper = new ResponseWrapper(request.getId(), request.getCodecType(), request.getProtocolType());
  responseWrapper.setException(new Exception("server threadpool full,maybe because server is slow or too many requests"));
  WriteFuture wf = session.write(responseWrapper);
  wf.addListener(new IoFutureListener() {
    public void operationComplete(IoFuture future) {
      if (!((WriteFuture) future).isWritten()) {
        LOGGER.error("server write response error,request id is: " + request.getId());
      }
    }
  });
}
 
开发者ID:leeyazhou,项目名称:nfs-rpc,代码行数:13,代码来源:MinaServerHandler.java

示例4: sessionOpened

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(final IoSession session) throws Exception {
    //log.info("IoSession with {} opened", session.getRemoteAddress());
    if (channel > -1) {
        if (ChannelServer.getInstance(channel).isShutdown()) {
            session.close();
            return;
        }
    }
    final byte[] key = {
        (byte) 0x13, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x06, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0xB4, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x1B, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x0F, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x33, (byte) 0x00, (byte) 0x00, (byte) 0x00,
        (byte) 0x52, (byte) 0x00, (byte) 0x00, (byte) 0x00
    };
    final byte[] ivRecv = {(byte) 70, (byte) 114, (byte) 122, (byte) 82};
    final byte[] ivSend = {(byte) 82, (byte) 48, (byte) 120, (byte) 115};
    ivRecv[3] = (byte) (Math.random() * 255.0d);
    ivSend[3] = (byte) (Math.random() * 255.0d);
    final MapleAESOFB sendCypher = new MapleAESOFB(key, ivSend, (short) (0xFFFF - MAPLE_VERSION));
    final MapleAESOFB recvCypher = new MapleAESOFB(key, ivRecv, MAPLE_VERSION);
    final MapleClient client = new MapleClient(sendCypher, recvCypher, session);
    client.setChannel(channel);
    session.write(MaplePacketCreator.getHello(MAPLE_VERSION, ivSend, ivRecv, false));
    session.setAttribute(MapleClient.CLIENT_KEY, client);
    session.setIdleTime(IdleStatus.READER_IDLE, 30);
    session.setIdleTime(IdleStatus.WRITER_IDLE, 30);
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:33,代码来源:MapleServerHandler.java

示例5: writeBody

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
/**
 * Asynchronously writes the given body to MINA session. Will wait at most for
 * 10 seconds until the body has been written.
 *
 * @param session  the MINA session
 * @param body     the body to write (send)
 * @param exchange the exchange
 * @throws CamelExchangeException is thrown if the body could not be written for some reasons
 *                                (eg remote connection is closed etc.)
 */
public static void writeBody(IoSession session, Object body, Exchange exchange) throws CamelExchangeException {
    // the write operation is asynchronous. Use WriteFuture to wait until the session has been written
    WriteFuture future = session.write(body);
    // must use a timeout (we use 10s) as in some very high performance scenarios a write can cause 
    // thread hanging forever
    LOG.trace("Waiting for write to complete for body: {} using session: {}", body, session);
    future.join(10000L);
    if (!future.isWritten()) {
        throw new CamelExchangeException("Cannot write body: " + body + " using session: " + session, exchange);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:MinaHelper.java

示例6: messageReceived

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void messageReceived(IoSession session, Object message) {
    // Reverse reveiced string
    String str = message.toString();
    StringBuilder buf = new StringBuilder(str.length());
    for (int i = str.length() - 1; i >= 0; i--) {
        buf.append(str.charAt(i));
    }

    // and write it back.
    session.write(buf.toString());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:12,代码来源:ReverseProtocolHandler.java

示例7: sessionOpened

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
public void sessionOpened(IoSession session) throws Exception {
    session.write("Hello there!\n");
    session.close();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:5,代码来源:MinaClientModeTcpTextlineDelimiterTest.java


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