Netty代理示例中ctx.write(Unpooled.EMPTY_BUFFER)的用途是什么(What's the purpose of ctx.write(Unpooled.EMPTY_BUFFER) in Netty proxy example)
在Netty 代理示例的
HexDumpProxyBackendHandler
中,channelActive
方法的代码如下:public void channelActive(ChannelHandlerContext ctx) { ctx.read(); ctx.write(Unpooled.EMPTY_BUFFER); }
我的问题是
ctx.write(Unpooled.EMPTY_BUFFER)
的目的是什么? 在通道激活后是否需要发送空的TCP消息帧?In
HexDumpProxyBackendHandler
of Netty proxy example , the code of the methodchannelActive
likes following:public void channelActive(ChannelHandlerContext ctx) { ctx.read(); ctx.write(Unpooled.EMPTY_BUFFER); }
My question is what's the purpose of
ctx.write(Unpooled.EMPTY_BUFFER)
? Is it necessary to send an empty TCP message frame after the channel active?
原文:https://stackoverflow.com/questions/33030331
满意答案
Node.js是制作实时框架以将用户链接到RESTful后端的不错选择。 但是,您也可以考虑使用托管实时消息服务(如PubNub)实时在用户和PHP后端之间传递数据。
使用PubNub的PHP Api ,您可以设置服务器以侦听事件:
$pubnub = new Pubnub( "demo", ## PUBLISH_KEY "demo", ## SUBSCRIBE_KEY "", ## SECRET_KEY false ## SSL_ON? ); $pubnub->subscribe(array( 'channel' => 'hello_world', ## REQUIRED Channel to Listen 'callback' => function($message) { ## REQUIRED Callback With Response ## Do all the awesome stuff your server does return true; ## Keep listening (return false to stop) } ));
现在您的服务器已订阅您的频道,您也可以让您的客户订阅,以收听全球事件。 我将从JavaScript SDK中给出一个示例,但是每个大型移动平台都有一个SDK:
var pubnub = PUBNUB.init({ publish_key : 'demo', subscribe_key : 'demo' }) function publish() { pubnub.publish({ channel : "hello_world", message : "Bob added Stan as a friend" }) } })();
您也可以反向执行此操作,以将消息从服务器广播到客户端。 巴姆!
最终,您可能希望为每个用户扩展您的应用程序,以便能够与服务器进行私密通信,以及身份验证; 我们称之为PubNub Access Manager,它受到了很大的支持。
祝你好运!
Node.js is a good choice to make a realtime framework to link your users to your RESTful backend. However, you may also consider using a hosted realtime messaging service such as PubNub to pass data between your users and your PHP backend in real time.
Using PubNub’s PHP Api, you can set up your server to listen for events:
$pubnub = new Pubnub( "demo", ## PUBLISH_KEY "demo", ## SUBSCRIBE_KEY "", ## SECRET_KEY false ## SSL_ON? ); $pubnub->subscribe(array( 'channel' => 'hello_world', ## REQUIRED Channel to Listen 'callback' => function($message) { ## REQUIRED Callback With Response ## Do all the awesome stuff your server does return true; ## Keep listening (return false to stop) } ));
Now that your server is subscribed to your channel, you can have your clients subscribe as well, to listen for global events. I’m going to give an example from the JavaScript SDK, but there’s an SDK for every sizable mobile platform as well:
var pubnub = PUBNUB.init({ publish_key : 'demo', subscribe_key : 'demo' }) function publish() { pubnub.publish({ channel : "hello_world", message : "Bob added Stan as a friend" }) } })();
You can also do this in reverse, to broadcast messages from the server to the clients. Bam!
Eventually you may want to extend your app with a unique channel for each user to be able to communicate privately with the server, and also authentication; we call this PubNub Access Manager and it is heavily supported.
Good luck!
相关问答
更多使用Node.js和Express进行简单的API调用(Simple API Calls with Node.js and Express)
Node.JS等待发出HTTP请求的REST Service的回调(Node.JS Wait for callback of REST Service that makes HTTP request)
为什么node.js一次只处理六个请求?(Why is node.js only processing six requests at a time?)
Node.js - 带cookie的多个请求(Node.js - multiple requests with cookies)
Node.js所有请求的静态头(Node.js static header for all requests)
使用node.js向Google API发出http请求(Making http request to Google API with node.js)
API.ai Node.js webhook的缓存响应(Caching response for API.ai Node.js webhook)
401.在Node.js中的GCM请求(401 on GCM requests in Node.js)
使用node.js向API发出请求(Making requests to API using node.js)
更大的项目Node.js和RESTful API(Bigger projects Node.js and RESTful API)
相关文章
更多[Netty 1] 初识Netty
Netty源码分析
storm学习之Netty代替ZMQ
Netty基于流的传输处理
Netty入门实例-时间服务器
Netty入门实例-使用POJO代替ByteBuf
在Twitter,Netty 4 GC开销降为五分之一
Netty环境配置
Netty开发环境配置
Netty入门实例-编写服务器端程序
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!