本文整理汇总了Java中io.netty.channel.Channel.writeAndFlush方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.writeAndFlush方法的具体用法?Java Channel.writeAndFlush怎么用?Java Channel.writeAndFlush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.writeAndFlush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: broadcastMess
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 广播普通消息
*
* @param message
*/
public static void broadcastMess(int uid, String nick, String message) {
if (!BlankUtil.isBlank(message)) {
try {
rwLock.readLock().lock();
Set<Channel> keySet = userInfos.keySet();
for (Channel ch : keySet) {
UserInfo userInfo = userInfos.get(ch);
if (userInfo == null || !userInfo.isAuth()) continue;
ch.writeAndFlush(new TextWebSocketFrame(ChatProto.buildMessProto(uid, nick, message)));
}
} finally {
rwLock.readLock().unlock();
}
}
}
示例2: handshake
import io.netty.channel.Channel; //导入方法依赖的package包/类
protected void handshake(HelloMessage request, Channel channel) {
try {
switch (getAuthScheme()) {
case CHALLENGE_RESPONSE:
handshakeChallengeResponse(request, channel);
break;
case NO_AUTH:
// shouldn't get here
break;
}
} catch (AuthException e) {
logger.warn("[{}->{}] Failed to authenticate connection: {}",
new Object[]{getLocalNodeIdString(),
getRemoteNodeIdString(),
e.getMessage()});
channel.writeAndFlush(getError(request.getHeader().getTransactionId(),
e, MessageType.HELLO));
channel.close();
}
}
示例3: userEventTriggered
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
Channel channel = ctx.channel();
if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
IdleStateEvent event = (IdleStateEvent) evt;
if (event.state() == IdleState.ALL_IDLE) {
//发送心跳
channel.writeAndFlush(PING);
}
if (event.state() == IdleState.READER_IDLE) {
//发送心跳
channel.writeAndFlush(PING);
}
if (event.state() == IdleState.WRITER_IDLE) {
channel.writeAndFlush(PING);
}
} else {
super.userEventTriggered(ctx, evt);
}
}
示例4: CloudNetClient
import io.netty.channel.Channel; //导入方法依赖的package包/类
public CloudNetClient(INetworkComponent iNetworkComponent, Channel channel)
{
this.networkComponent = iNetworkComponent;
this.networkComponent.setChannel(channel);
this.channel = channel;
System.out.println("Channel connected [" + channel.remoteAddress().toString() + "/serverId=" + networkComponent.getServerId() + "]");
if(networkComponent instanceof Wrapper)
{
StatisticManager.getInstance().wrapperConnections();
System.out.println("Wrapper [" + networkComponent.getServerId() + "] is connected.");
CloudNet.getInstance().getEventManager().callEvent(new WrapperChannelInitEvent((Wrapper) networkComponent, channel));
CloudNet.getInstance().getDbHandlers().getWrapperSessionDatabase().addSession(new WrapperSession(UUID.randomUUID(), ((Wrapper)networkComponent).getNetworkInfo(), System.currentTimeMillis()));
((Wrapper)networkComponent).updateWrapper();
}
CloudNetwork cloudNetwork = CloudNet.getInstance().getNetworkManager().newCloudNetwork();
channel.writeAndFlush(new PacketOutCloudNetwork(cloudNetwork));
if(networkComponent instanceof MinecraftServer)
{
((MinecraftServer)networkComponent).setChannelLostTime(0L);
networkComponent.getWrapper().sendPacket(new PacketOutOnlineServer(((MinecraftServer)networkComponent).getServerInfo()));
}
if(networkComponent instanceof ProxyServer)
{
((ProxyServer)networkComponent).setChannelLostTime(0L);
}
CloudNet.getInstance().getEventManager().callEvent(new ChannelInitEvent(channel, networkComponent));
init(cloudNetwork);
}
示例5: handleSyncOffer
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void handleSyncOffer(SyncOfferMessage request,
Channel channel) {
try {
String storeName = request.getStore().getStoreName();
SyncRequestMessage srm = new SyncRequestMessage();
AsyncMessageHeader header = new AsyncMessageHeader();
header.setTransactionId(request.getHeader().getTransactionId());
srm.setHeader(header);
srm.setStore(request.getStore());
for (KeyedVersions kv : request.getVersions()) {
Iterable<org.sdnplatform.sync.thrift.VectorClock> tvci =
kv.getVersions();
Iterable<VectorClock> vci = new TVersionIterable(tvci);
boolean wantKey = syncManager.handleSyncOffer(storeName,
kv.getKey(), vci);
if (wantKey)
srm.addToKeys(kv.bufferForKey());
}
SyncMessage bsm =
new SyncMessage(MessageType.SYNC_REQUEST);
bsm.setSyncRequest(srm);
if (logger.isTraceEnabled()) {
logger.trace("[{}->{}] Sending SyncRequest with {} elements",
new Object[]{getLocalNodeIdString(),
getRemoteNodeIdString(),
srm.getKeysSize()});
}
channel.writeAndFlush(bsm);
} catch (Exception e) {
channel.writeAndFlush(getError(request.getHeader().getTransactionId(),
e, MessageType.SYNC_OFFER));
}
}
示例6: action
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void action(Channel ch, Proto proto) throws Exception {
// write heartbeat reply
proto.setOperation(Constants.OP_HEARTBEAT_REPLY);
proto.setBody(null);
ch.writeAndFlush(proto);
}
示例7: call
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void call(ChannelHandlerContext ctx, Ping message) {
Channel channel = ctx.channel();
channel.writeAndFlush(PONG);
saveLiveDc(channel);
log.debug("node send pong to data center, channel:{}", ctx.channel());
}
示例8: sendRemote
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 给remoteserver发送数据--需要进行加密处理
*
* @param data
* @param length
* @param channel
*/
public void sendRemote(byte[] data, int length, Channel channel) {
if(isProxy) {
_crypt.encrypt(data, length, _remoteOutStream);
data = _remoteOutStream.toByteArray();
}
channel.writeAndFlush(Unpooled.wrappedBuffer(data));
logger.debug("sendRemote message:isProxy = " + isProxy +",length = " + length+",channel = " + channel);
}
示例9: broadPing
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 心跳检测Ping
*/
public void broadPing(){
try{
rwLock.readLock().lock();
logger.info("broadCastPing userCount: {}", userCount.intValue());
Set<Channel> keySet = chatUserMap.keySet();
for (Channel ch : keySet) {
ChatUser cUser = chatUserMap.get(ch);
if (cUser == null || !cUser.isAuth()) continue;
ch.writeAndFlush(new TextWebSocketFrame(QuarkChatProtocol.buildPing()));
}
}finally {
rwLock.readLock().unlock();
}
}
示例10: send
import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void send( Channel ctx, final byte[] data) {
if (ctx == null)
return;
final ByteBuf byteBufMsg = ctx.alloc().buffer(data.length);
byteBufMsg.writeBytes(data);
ctx.writeAndFlush(byteBufMsg);
}
示例11: send
import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void send(final Channel ctx, final byte[] data) {
if (ctx == null)
return;
final ByteBuf byteBufMsg = ctx.alloc().buffer(data.length);
byteBufMsg.writeBytes(data);
ctx.writeAndFlush(byteBufMsg);
}
示例12: sentToClient
import io.netty.channel.Channel; //导入方法依赖的package包/类
private void sentToClient(RemotingCommand request){
Map<String,Set<Channel>> groupChannelTable = this.producerManager.getGroupChannelTable();
if(groupChannelTable.get(request.getGroup()) == null ||
CollectionUtils.isEmpty(groupChannelTable.get(request.getGroup()))){
return;
}
List<Channel> channels = Lists.newArrayList(groupChannelTable.get(request.getGroup()));
Channel c = channels.get(new Random().nextInt(channels.size()));
if(c.isActive()){
c.writeAndFlush(request);
}
}
示例13: unexpectedMessage
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* Send an error to the channel indicating that we got an unexpected
* message for this type of RPC client
* @param transactionId the transaction ID for the message that generated
* the error
* @param type The type of the message that generated the error
* @param channel the channel to write the error
*/
protected void unexpectedMessage(int transactionId,
MessageType type,
Channel channel) {
String message = "Received unexpected message: " + type;
logger.warn("[{}->{}] {}",
new Object[]{getLocalNodeIdString(),
getRemoteNodeIdString(),
message});
channel.writeAndFlush(getError(transactionId,
new SyncException(message), type));
}
示例14: call
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void call(ChannelHandlerContext ctx, NodeInfoReq message) {
Channel channel = ctx.channel();
channel.writeAndFlush(NodeInfoResp.builder().result(NodeMessageEnum.OK.getCode()).build().encode());
log.debug("receive nodeInfoReq,channel:{}", channel);
}
示例15: sendPong
import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void sendPong(Channel channel) {
channel.writeAndFlush(new TextWebSocketFrame(ChatProto.buildPongProto()));
}