本文整理匯總了TypeScript中json-rpc2.Client類的典型用法代碼示例。如果您正苦於以下問題:TypeScript Client類的具體用法?TypeScript Client怎麽用?TypeScript Client使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Client類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: test
test('TCP/HTTP RPC command', function (done) {
var server = new stratum.RPCServer(_.defaults({ mode: 'both' }, this.opts)),
exposed = {
'func': function (args, opts, callback) {
callback(null, args)
}
},
spy = sinon.spy(exposed, 'func'),
client = new rpc.Client(server.opts.port, 'localhost')
server.expose('func', exposed.func, exposed).listen()
client.connectSocket(function (err, conn) {
conn.call('func', ['MTIz', 1, 2], function (err, result) {
expect(result).to.eql([1, 2])
expect(spy.calledWith([1, 2])).to.equal(true)
client.call('func', ['MTIz', 1, 2], function (err, result) {
expect(result).to.eql([1, 2])
expect(spy.calledWith([1, 2])).to.equal(true)
server.close()
done()
})
})
})
})
示例2: connectClient
function connectClient(port: number, host: string) {
let client = Client.$create(port, host);
client.connectSocket((err, conn) => {
if (err) return reject(err);
// Add a slight delay to avoid issues on Linux with
// Delve failing calls made shortly after connection.
setTimeout(() =>
resolve(conn),
200);
});
}
示例3: function
conn.call('func', ['MTIz', 1, 2], function (err, result) {
expect(result).to.eql([1, 2])
expect(spy.calledWith([1, 2])).to.equal(true)
client.call('func', ['MTIz', 1, 2], function (err, result) {
expect(result).to.eql([1, 2])
expect(spy.calledWith([1, 2])).to.equal(true)
server.close()
done()
})
})