本文整理汇总了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...");
}