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


Java IoSession.write方法代码示例

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


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

示例1: sendChannelExcept

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
private void sendChannelExcept(TCMessage message, int teamNum, int channelId, UnrealId except) {
	TCTeam team = teams.get(teamNum);
	if (team == null) return;
	TCChannel channel = team.getChannels().get(channelId);
	if (channel == null) return;
	synchronized(channel) {
		synchronized(channel.getConnectedBots()) {
			for (UnrealId target : channel.getConnectedBots()) {
				if (target == except) continue;
				IoSession targetSession = botSessions.get(target);
				synchronized(targetSession) {
					targetSession.write(message);
				}
			}
		}
	}
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:18,代码来源:TCMinaServer.java

示例2: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 收到来自客户端的消息
 */
@Override
public void messageReceived(IoSession session, Object message)
        throws Exception {
 
    String clientIP = session.getRemoteAddress().toString();
    log.debug("服务端接收到来自IP:"+clientIP+"的消息:"+message);
    //TODO 收到消息后调用对应解码器处理对应事件
    
    //TODO 用户验证 收到消息的时候判断是否是非法连接
    //###Key###MessageLength###Content###
    
    //TODO 指令验证
    
    //TODO 执行指令
    
    session.write("ok");
    //测试map内部值
    if(message.toString().equals("999")){
    	for (Entry<Long, String> entry : map.entrySet()) {  
            Long key = entry.getKey();  
            String value = entry.getValue().toString();  
            System.out.println("key =" + key + " value = " + value);  
        }
    }
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:29,代码来源:ServerHandler.java

示例3: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(IoSession session){
	BaseMessage baseMessage = new BaseMessage();
	baseMessage.setDataType(BeanUtil.UPLOAD_FILE);
	FileBean bean = new FileBean();

	File file = new File("D:\\照片\\2013年\\松风寨\\IMG_9214.jpg");

	bean.setFileName(file.getName());
	bean.setFileSize((int)file.length());
	try {
		FileHelper helper =new FileHelper();
		bean.setFileContent(helper.getContent(file));
	} catch (Exception e) {

		e.printStackTrace();
	}
	baseMessage.setData(bean);
	session.write(baseMessage); 
}
 
开发者ID:Xvms,项目名称:xvms,代码行数:21,代码来源:ClientHandler.java

示例4: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened ( final NextFilter nextFilter, final IoSession session ) throws Exception
{
    logger.debug ( "Session opened: {}", session );

    final IoBuffer buffer = IoBuffer.allocate ( 1 );
    buffer.setAutoExpand ( true );

    buffer.put ( new byte[] { 0x11, (byte)0xE0, 0x00, 0x00, 0x00, 0x01, 0x00, (byte)0xC1, 2, 1, 0, (byte)0xC2, 2, 0, 1, (byte)0xC0, 1, 9 } );

    buffer.put ( 13, (byte) ( this.rack + 1 ) );
    buffer.put ( 14, this.slot );

    buffer.flip ();

    session.write ( buffer );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:18,代码来源:COTPFilter.java

示例5: lock

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 获取数据
 * 
 * @param ioSession
 *            链接句柄
 * @param tcpPacket
 *            消息包
 * @return
 */
public static TcpPacket lock(IoSession ioSession, TcpPacket tcpPacket) {
	// 获取锁
	WaitLock waitLock = getWaitLock();
	// 设置此进程唯一id
	tcpPacket.lockedId = waitLock.getInstanceId();
	// 同步块
	synchronized (waitLock) {
		// 发送消息
		ioSession.write(tcpPacket);
		try {
			// 等待解锁
			waitLock.wait(waitLockTime);
		} catch (InterruptedException e) {
			if (MinaConfig.log != null) {
				MinaConfig.log.error("获取数据超时", e);
			}
		}
	}
	// 解锁成功返回数据
	return waitLock.getTcpPacket();
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:31,代码来源:WaitLockManager.java

示例6: onServerConnected

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public void onServerConnected(MsgPacket msgPacket) {
	IoSession session = (IoSession) msgPacket.getOtherData();
	System.out.println("接到消息:" + msgPacket.getMsgOpCode());
	RPCTestC.Builder builder = RPCTestC.newBuilder();
	builder.setName("RPC你好啊");
	TcpPacket pt = new TcpPacket(TestTCode.TEST_RPC_C, builder.build());

	TcpPacket ptReturn = WaitLockManager.lock(session, pt);
	RPCTestS rpcTestS = (RPCTestS) ptReturn.getData();
	System.out.println("接到RPC消息:" + rpcTestS.getName());

	RPCTestC.Builder builder1 = RPCTestC.newBuilder();
	builder1.setName("TCP你好啊");
	TcpPacket pt1 = new TcpPacket(TestTCode.TEST_RPC_C, builder1.build());
	session.write(pt1);

}
 
开发者ID:dianbaer,项目名称:grain,代码行数:18,代码来源:TestMsgService.java

示例7: writeWebSocketV6Fram

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public static void writeWebSocketV6Fram(IoSession out, byte[] data,
		int type, boolean mark, boolean haveMore) throws IOException {
	WebSocketV6Fram fram = new WebSocketV6Fram();
	if (!haveMore)
		fram.setFin(FIN);
	if (type <= 0 || type > 16)
		throw new IllegalArgumentException("0 < type <= 16");
	fram.setOpcode((byte) type);
	if (mark)
		fram.setMask(MASK);
	int length = data.length;
	fram.setDateLength(length);
	out.write(fram.toByte());
	if (mark) {
		byte[] bt = fram.getMaskingKey();
		for (int i = 0; i < length; i++) {
			byte b = data[i];
			b ^= bt[i % 4];
			out.write(b);
		}
	} else {
		out.write(data);
	}
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:25,代码来源:WebSocketV6Fram.java

示例8: onServerConnected

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
public void onServerConnected(MsgPacket msgPacket) {
	IoSession session = (IoSession) msgPacket.getOtherData();
	System.out.println("接到消息:" + msgPacket.getMsgOpCode());
	TestC.Builder builder = TestC.newBuilder();
	builder.setName("你好啊");
	TcpPacket pt = new TcpPacket(TestTCode.TESTC, builder.build());
	session.write(pt);
}
 
开发者ID:dianbaer,项目名称:grain,代码行数:9,代码来源:TestMsgService.java

示例9: sendPrivate

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
private void sendPrivate(TCMessage message, UnrealId target) {
	IoSession targetSession = botSessions.get(target);
	if (targetSession != null) {
		synchronized(targetSession) {
			targetSession.write(message);
		}
	}
}
 
开发者ID:kefik,项目名称:Pogamut3,代码行数:9,代码来源:TCMinaServer.java

示例10: doExec

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void doExec(TcpMessage message, IoSession session) {
	CjyTcpMessage tcpMsg = (CjyTcpMessage)message;
	//TODO解析数据并入库
	byte[] data1 = tcpMsg.getData();
	ByteBuffer buf = ByteBuffer.wrap(data1);
	////通道0交流有效值,单位1mV交流干扰电压
	int ch0_effictive_value = CommUtils.highAndLowAddressSwap(buf.getInt());
	 //通道1 直流中位值,单位10uV自 然电位
	int ch1_middle_value = CommUtils.highAndLowAddressSwap(buf.getInt());
	////通道2 继电器闭合时直流中位值,10uV通电电位
	int ch2_middle_connect_value = CommUtils.highAndLowAddressSwap(buf.getInt());
	//通道2 继电器断开时直流中位值,10uV断电电位
	int ch2_middle_disconnect_value = CommUtils.highAndLowAddressSwap(buf.getInt());
	
	CjyTcpMessage dataReq = new CjyTcpMessage();
	dataReq.setAddress(tcpMsg.getAddress());
	dataReq.setCmd(TcpNetCmd.ACK & TcpNetCmd.SET_TIME_ID);
	String curDate = CommUtils.formatDate(new Date(Calendar.getInstance().getTimeInMillis()), "yy-M-dd-H-m-s");
	String[] ele = curDate.split("-");
	dataReq.setLength(ele.length);
	byte[] data = new byte[ele.length];
	for(int i = 0; i < ele.length; i ++){
		data[i] = CommUtils.parseByte(ele[i]);
	}
	dataReq.setData(data);
	session.write(dataReq);
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:29,代码来源:DataGetMessageHandler.java

示例11: writeFrame

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 协议00发送消息
 * @param out
 * @param content
 * @throws IOException
 */
public static void writeFrame(IoSession session, String content)throws IOException {
	byte[] ab = content.getBytes(CHARSET_UTF8);
	IoBuffer buffer=IoBuffer.allocate(ab.length + 2);
	buffer.put((byte)0x00);
	buffer.put(ab);
	buffer.put((byte)0xFF);
	buffer.flip(); 
	session.write(buffer);
}
 
开发者ID:langxianwei,项目名称:iot-plat,代码行数:16,代码来源:Tools.java

示例12: sessionOpened

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void sessionOpened(IoSession session) throws Exception {
	String ipAddr = SessionManager.INSTANCE.getRemoteIp(session);
	if (!isInWhiteIps(ipAddr)) {
		logger.error("非法后台登录,remoteIp=[{}]", ipAddr);
		byte[] body = "too young too simple".getBytes("UTF-8");
		IoBuffer out = IoBuffer.allocate(body.length);
		out.put(body);
		out.flip();
		session.write(out);
		session.close(false);
	}
}
 
开发者ID:kingston-csj,项目名称:jforgame,代码行数:14,代码来源:HttpServer.java

示例13: handlePacket

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void handlePacket(SeekableLittleEndianAccessor slea, IoSession session) {
    List<String> playerList = new ArrayList<String>();
    for (Channel ch : Server.getInstance().getAllChannels()) {
        Collection<MapleCharacter> list = ch.getPlayerStorage().getAllCharacters();
        synchronized (list) {
            for (MapleCharacter chr : list) {
                if (!chr.isGM()) {
                    playerList.add(chr.getName());
                }
            }
        }
    }
    session.write(GMPacketCreator.sendPlayerList(playerList));
}
 
开发者ID:NovaStory,项目名称:AeroStory,代码行数:16,代码来源:PlayerListHandler.java

示例14: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
/**
 * 当客户端收到服务器的消息后触发此方法.
 * @param session IoSession对象
 * @param message 客户端收到消息对象
 * @throws Exception
 */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    String str = message.toString();
    if (str.trim().equalsIgnoreCase("quit")) {
        session.close();
        return;
    }
    Date date = new Date();
    // 无论客户端发来什么消息,服务器只是把当前日期发送回去
    session.write(date.toString());
    System.out.println("Message written...");
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:19,代码来源:TimeServerHandler.java

示例15: messageReceived

import org.apache.mina.core.session.IoSession; //导入方法依赖的package包/类
@Override
public void messageReceived(IoSession session, Object message) throws Exception {

	String str = message.toString();
	System.out.println("接受到的消息:" + str);
	if (str.trim().equalsIgnoreCase("quit")) {
		session.close(true);
		return;
	}
	Date date = new Date();
	session.write(date.toString());
	System.out.println("Message written...");
}
 
开发者ID:handexing,项目名称:frameworkAggregate,代码行数:14,代码来源:TimeServerHandler.java


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