This action will force synchronization from Hprose/hprose-nodejs, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
Hprose is a High Performance Remote Object Service Engine.
It is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.
Hprose supports many programming languages, for example:
Through Hprose, You can conveniently and efficiently intercommunicate between those programming languages.
This project is the implementation of Hprose for Node.js.
Hprose for Node.js is very easy to use. You can create a hprose server like this:
var hprose = require("hprose");
function hello(name) {
return "Hello " + name + "!";
}
var server = hprose.Server.create("http://0.0.0.0:8080");
server.addFunction(hello);
server.start();
To start it use:
node --harmony server.js
--harmony is a v8 options, hprose use it to optimize serialization. This is not required option, but it is recommended to use it.
In fact most nodejs service methods are asynchronous, you can publish asynchronous function like this:
var hprose = require("hprose");
function hello(name, callback) {
setTimeout(function() {
callback("Hello " + name + "!");
}, 10);
}
var server = hprose.Server.create("http://0.0.0.0:8080");
server.addAsyncFunction(hello);
server.start();
Then you can create a hprose client to invoke it like this:
var hprose = require("hprose");
var client = hprose.Client.create("http://127.0.0.1:8080/");
var proxy = client.useService();
proxy.hello("world", function(result) {
console.log(result);
});
To start it use:
node --harmony client.js
or
node --harmony-proxies client.js
Without --harmony-proxies, you need create proxy like this:
var hprose = require("hprose");
var client = hprose.Client.create("http://127.0.0.1:8080/");
var proxy = client.useService(["hello"]);
proxy.hello("world", function(result) {
console.log(result);
});
Or create client like this:
var hprose = require("hprose");
var client = hprose.Client.create("http://127.0.0.1:8080/", ["hello"]);
client.hello("world", function(result) {
console.log(result);
});
If an error occurred on the server, or your service function/method throw an exception, it will be sent to the client. You need to pass an error callback function after succuss callback function to receive it. If you omit this callback function, the client will ignore the exception, like never happened.
For example:
proxy.hello("world", function(result) {
console.log(result);
}, function(name, err) {
console.error(err);
});
The Tcp Server & Client are used as same as the Http Server & Client.
To create a Tcp Server:
var server = hprose.Server.create("tcp://0.0.0.0:4321");
To create a Tcp Client:
var client = hprose.Client.create('tcp://127.0.0.1:4321');
The Unix Socket Server & Client are used as same as the Http Server & Client.
To create a Unix Socket Server:
var server = hprose.Server.create("unix:/tmp/my.sock");
To create a Unix Socket Client:
var client = hprose.Client.create('unix:/tmp/my.sock');
The WebSocket Server & Client are used as same as the Http Server & Client.
To create a WebSocket Server:
var server = hprose.Server.create("ws://0.0.0.0:8080/");
To create a WebSocket Client:
var client = hprose.Client.create('ws://0.0.0.0:8080/');
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。