本文整理匯總了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);
}
}
}
}
}
示例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);
}
}
}
示例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);
}
示例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 );
}
示例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();
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
}
示例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));
}
示例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...");
}
示例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...");
}