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