當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。