hprose 3.0.3

Hprose

Hprose 3.0 for Dart #

Join the chat Build Status Pub

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:

  • AAuto Quicker
  • ActionScript
  • ASP
  • C++
  • Dart
  • Delphi/Free Pascal
  • dotNET(C#, Visual Basic...)
  • Golang
  • Java
  • JavaScript
  • Node.js
  • Objective-C
  • Perl
  • PHP
  • Python
  • Ruby
  • ...

Through Hprose, You can conveniently and efficiently intercommunicate between those programming languages.

This project is the implementation of Hprose for Dart.

3.0.0-beta.1 #

  • Initial version, created by andot

3.0.0-beta.2 #

  • Fixed some hints.
  • Added CHANGELOG.md.

3.0.0-beta.3 #

  • Fixed some hints.

3.0.0-beta.4 #

  • Fixed some hints.
  • Added flutter, web and other platforms support.

3.0.0 #

  • Added Dart 2.0 support.
  • Added Flutter support.
  • Added Service implementation.
  • Added TCP, UDP, WebSocket support.
  • Added middleware support.
  • Added JSONRPC support.
  • Added Circuit Breaker plugin.
  • Added Cluster plugin.
  • Added Limiter plugin.
  • Added Load Balance plugin.
  • Added Log plugin.
  • Added Oneway call plugin.
  • Added Push plugin.
  • Added Reverse RPC plugin.

3.0.1 #

  • Added headers on JsonRpc.
  • Added exists & idlist for caller.
  • Added names property on Service.
  • Fixed ClientContext.
  • Fixed oneway plugin.
  • Fixed ConcurrentLimiter plugin.
  • Added remoteAddress & localAddress on ServiceContext.
  • Added request method on Client.
  • Improved Method.
  • Added httpStatusCode & httpStatusText on ClientContext.

3.0.2 #

  • Added google app engine support.

3.0.3 #

  • Improved google app engine support.

example/main.dart

library hprose_example;

import 'dart:async';
import 'dart:io';
import 'package:hprose/io.dart';
import 'package:hprose/rpc.dart';

String hello(String name) {
  return 'hello $name';
}

Future<int> sum(int a, int b, [int c = 0, int d = 10]) async {
  await Future.delayed(new Duration(milliseconds: 1));
  return a + b + c + d;
}

String getAddress(String name, ServiceContext context) {
  return '$name : ${context.host}';
}

class User {
  String name;
  int age;
  bool male;
  User([this.name, this.age, this.male]);
  factory User.fromJson(Map<String, dynamic> json) {
    return new User(json['name'], json['age'], json['male']);
  }
  Map<String, dynamic> toJson() =>
      {'name': this.name, 'age': this.age, 'male': this.male};
}

User createUser(String name, {int age, bool male, Context context}) {
  final serviceContext = context as ServiceContext;
  print('${serviceContext.remoteAddress.host}:${serviceContext.remotePort}');
  return new User(name, age, male);
}

void main() async {
  TypeManager.register((data) => User.fromJson(data),
      {'name': String, 'age': int, 'male': bool});
  final service = new Service();
  service
    ..addMethod(hello)
    ..addMethod(sum)
    ..addMethod(getAddress)
    ..addMethod(createUser);
  final server = await HttpServer.bind('127.0.0.1', 8000);
  service.bind(server);
  final client = new Client(['http://127.0.0.1:8000/']);
  final proxy = client.useService();
  print(await proxy.hello<String>('world'));
  final r1 = proxy.sum<int>(1, 2);
  final r2 = proxy.sum<int>(1, 2, 3);
  print(await proxy.sum<int>(r1, r2, 3, 4));
  print(await proxy.getAddress<String>('localhost'));
  User user = await proxy.createUser<User>('张三', age: 18, male: true);
  print(user);
  server.close();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  hprose: ^3.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:hprose/hprose.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
98
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
63
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:hprose/hprose.dart.

Health suggestions

Fix lib/src/rpc/http_handler.dart. (-0.50 points)

Analysis of lib/src/rpc/http_handler.dart reported 1 hint:

line 174 col 37: DO use curly braces for all flow control structures.

Fix lib/src/rpc/http_transport.dart. (-0.50 points)

Analysis of lib/src/rpc/http_transport.dart reported 1 hint:

line 75 col 44: DO use curly braces for all flow control structures.

Fix lib/src/rpc/plugins/oneway.dart. (-0.50 points)

Analysis of lib/src/rpc/plugins/oneway.dart reported 1 hint:

line 24 col 7: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Fix lib/src/rpc/websocket_handler.dart. (-0.50 points)

Analysis of lib/src/rpc/websocket_handler.dart reported 1 hint:

line 36 col 7: Future results in async function bodies must be awaited or marked unawaited using package:pedantic.

Format lib/src/rpc/core/method.dart.

Run dartfmt to format lib/src/rpc/core/method.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test any