All Projects → metarhia → metacom

metarhia / metacom

Licence: MIT license
RPC communication protocol for Metarhia stack 🔌

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to metacom

Jstp
Fast RPC for browser and Node.js based on TCP, WebSocket, and MDSF
Stars: ✭ 132 (+214.29%)
Mutual labels:  tcp, ipc, protocol, rpc
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (-21.43%)
Mutual labels:  highload, metarhia, impress
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-52.38%)
Mutual labels:  ipc, protocol, rpc
metaschema
Schema definition and validation 💡
Stars: ✭ 25 (-40.48%)
Mutual labels:  metarhia, impress, meta-edu
InterProcessCommunication
Inter-process Communication
Stars: ✭ 11 (-73.81%)
Mutual labels:  tcp, ipc, rpc
Scalecube Services
v2.0 - ScaleCube Services provides a low latency Reactive Microservices library for serverless service registry and discovery based on gossip protocol and without single point-of-failure or bottlenecks.
Stars: ✭ 23 (-45.24%)
Mutual labels:  tcp, ipc, rpc
Workerman
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.3.
Stars: ✭ 9,617 (+22797.62%)
Mutual labels:  tcp, wss, ws
Ttrpc
GRPC for low-memory environments
Stars: ✭ 236 (+461.9%)
Mutual labels:  stream, protocol, rpc
workerman
An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols. PHP>=5.4.
Stars: ✭ 10,005 (+23721.43%)
Mutual labels:  tcp, wss, ws
Contracts
Metarhia core docs and contracts specifications 📒
Stars: ✭ 26 (-38.1%)
Mutual labels:  metarhia, impress
RRQMSocket
TouchSocket是.Net(包括 C# 、VB.Net、F#)的一个整合性的、超轻量级的网络通信框架。包含了 tcp、udp、ssl、http、websocket、rpc、jsonrpc、webapi、xmlrpc等一系列的通信模块。一键式解决 TCP 黏分包问题,udp大数据包分片组合问题等。使用协议模板,可快速实现「固定包头」、「固定长度」、「区间字符」等一系列的数据报文解析。
Stars: ✭ 286 (+580.95%)
Mutual labels:  tcp, rpc
SuperSimpleTcp
Simple wrapper for TCP client and server in C# with SSL support
Stars: ✭ 263 (+526.19%)
Mutual labels:  tcp, rpc
common
Metarhia Common Library
Stars: ✭ 55 (+30.95%)
Mutual labels:  metarhia, impress
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (-9.52%)
Mutual labels:  tcp, protocol
SierraChartZorroPlugin
A Zorro broker API plugin for Sierra Chart, written in Win32 C++.
Stars: ✭ 22 (-47.62%)
Mutual labels:  tcp, protocol
node-drivers
Industrial protocol drivers in node.js
Stars: ✭ 20 (-52.38%)
Mutual labels:  tcp, protocol
muxrpc
lightweight multiplexed rpc
Stars: ✭ 96 (+128.57%)
Mutual labels:  protocol, rpc
missive
Fast, lightweight library for encoding and decoding JSON messages over streams.
Stars: ✭ 16 (-61.9%)
Mutual labels:  stream, tcp
Ether1
Official Go implementation of The Etho Protocol
Stars: ✭ 41 (-2.38%)
Mutual labels:  ipc, rpc
net-protocol
golang模拟内核协议栈 实现链路层、网络层、传输层、应用层 用户态协议栈 ,基于虚拟网卡TUN/TAP
Stars: ✭ 129 (+207.14%)
Mutual labels:  tcp, protocol

Metacom Communication Protocol for Metarhia

ci status snyk npm version npm downloads/month npm downloads

Metacom protocol specification: https://github.com/metarhia/Contracts/blob/master/doc/Metacom.md

// Load at frontend
import { Metacom } from './metacom.js';

// Load at backend
const { Metacom } = require('metacom');

// Open connection (both platforms) and make calls
const metacom = Metacom.create('https://domainname.com:8000');
(async () => {
  const { api } = metacom;
  try {
    await metacom.load('auth'); // Load `auth` interface
    await api.auth.status(); // Check session status
  } catch (err) {
    await api.auth.signIn({ login: 'marcus', password: 'marcus' });
  }
  await metacom.load('example'); // Load `example` interface
  const result = api.example.methodName({ arg1, arg2 });
})();

Streams over Websocket

Example: big file upload

Create uploadFile function on the client:

const metacom = Metacom.create('https://example.com/api');

const uploadFile = async (file) => {
  // createBlobUploader creates streamId and inits file reader for convenience
  const uploader = metacom.createBlobUploader(file);
  // Prepare backend file consumer
  await metacom.api.files.upload({
    streamId: uploader.streamId,
    name: file.name,
  });
  // Start uploading stream and wait for its end
  await uploader.upload();
  return { uploadedFile: file };
};

Create API method to init file destination:

// api/files/upload.js
async ({ streamId, name }) => {
  const filePath = `./application/resources/${name}`;
  // Get incoming stream by streamId sent from client
  const readable = context.client.getStream(streamId);
  // Create nodejs stream to write file on server
  const writable = node.fs.createWriteStream(filePath);
  // Pipe metacom readable to nodejs writable
  readable.pipe(writable);
  return { result: 'Stream initialized' };
};

Example: big file download

Create downloadFile function on the client:

const metacom = Metacom.create('https://example.com/api');

const downloadFile = async (name) => {
  // Init backend file producer to get streamId
  const { streamId } = await metacom.api.files.download({ name });
  // Get metacom readable stream
  const readable = await metacom.getStream(streamId);
  // Convert stream to blob to make a file on the client
  const blob = await readable.toBlob();
  return new File([blob], name);
};

Create API method to init file source:

// api/files/download.js
async ({ name }) => {
  const filePath = `./application/resources/${name}`;
  // Create nodejs readable stream to read a file
  const readable = node.fs.createReadStream(filePath);
  // Get file size
  const { size } = await node.fsp.stat(filePath);
  // Create metacom writable stream
  const writable = context.client.createStream(name, size);
  // Pipe nodejs readable to metacom writable
  readable.pipe(writable);
  return { streamId: writable.streamId };
};

License & Contributors

Copyright (c) 2018-2022 Metarhia contributors. Metacom is MIT licensed.
Metacom is a part of Metarhia technology stack.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].