I use dnode
I have read StackOverflow: Send message from server to client with dnode
and undersand
dnode uses a symmetric protocol so either side can define functions that the opposing side can call.
as @substack the author replied.
So, right now, I have a code as the below:
var HTTPserver = httpServer('/www')
.listen(9999, function()
{
console.log('HTTP listening 9999');
});
var dnode = require('dnode');
var shoe = require('shoe')(
function(stream)
{
var TCPserver = require('net')
.createServer()
.listen(5005, function()
{
console.log('TCP listening 5005');
})
.on('connection', function(socket)
{
console.log('TCPsocket connected');
var d = dnode(
{
});
d.on('remote', function(remote)
{
remote.test();
});
d
.pipe(stream)
.pipe(d);
socket.end();
})
.on('end', function()
{
console.log('TCPsocket disconnected');
});
})
.install(HTTPserver, '/dnode');
var shoe = require('shoe');
var stream = shoe('/dnode');
var dnode = require('dnode');
var d = dnode(
{
test: function()
{
console.log('hello');
}
});
d.on('remote', function(remote)
{
console.log('connnected');
});
d.pipe(stream)
.pipe(d);
Basically, I want to call function:test -> hello initiated from server.
However, the result I see is
d.on('remote', function(remote) { console.log('connnected'); });
@ client is evaluated.
d.on('remote', function(remote) { remote.test(); });
@ server is never evaluated.
Why is that?
Of course, probably I can work around using client->server->client call back method, but if possible I just would like the straight forward way for my future work.
Thanks.
我发现答案很简单,在TCP套接字回调中生成事件定义中的dnode d.on是个坏主意,因为在尚未触发dnode之前,还没有dnode东西。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.