Socket
Socket
Sign inDemoInstall

websocket-rpcs

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket-rpcs

rpc over websocket uses protobuf to serialize data


Maintainers
1

rpc over websocket uses protobuf to serialize data

Prepare

install package

pip install websocket-rpcs

write proto file (math.proto)

syntax = "proto3";

option py_generic_services = true;

message SumArg {
    int32 a = 1;
    int32 b = 2;
}

message SumResult {
    int32 sum = 1;
}

service Math {
    rpc Sum(SumArg) returns (SumResult);
}

generate python file (math_pb2.py math_pb2.pyi)

protoc --python_out=. --pyi_out=. math.proto

Example

Server

import wrpc
import math_pb2
def sum(args):
    return {
        "sum": args["a"] + args["b"]
    }
wrpc_server = wrpc.WebSocketRPCServer("0.0.0.0", 5887)
wrpc_server.add_handler("Math.Sum", sum_pb2.SumArg,sum_pb2.SumResult, sum)
wrpc_server.start()

Client

import wrpc
import math_pb2
wrpc_client = wrpc.WebSocketRpcClient("ws://localhost:5887")
sum_client = wrpc_client.init(sum_pb2.Sum_Stub, sum_pb2.SumArg, sum_pb2.SumResult)
res = sum_client.call("Sum", a=1, b=2)

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc