Skip to content

How to set up an RPC server on a tokio::DuplexStream? #1456

Answered by AArnott
AArnott asked this question in Q&A
Discussion options

You must be logged in to vote

I figured this out. Here is a client that works off of DuplexStream:

use async_trait::async_trait;
use jsonrpsee::{
    async_client::{Client, ClientBuilder},
    core::client::{ReceivedMessage, TransportReceiverT, TransportSenderT},
    proc_macros::rpc,
};
use tokio::io::{
    duplex, split, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt, DuplexStream, ReadHalf,
    WriteHalf,
};

#[tokio::main]
async fn main() {
    let (client_stream, server_stream) = duplex(1024);

    tokio::spawn(mock_server(server_stream));

    let client = build_client(client_stream);
    let sum = client.add(3, 5).await.unwrap();
    println!("{}", sum);
}

async fn mock_server(mut pipe: DuplexStream) -> Re…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@AArnott
Comment options

Comment options

You must be logged in to vote
1 reply
@AArnott
Comment options

Answer selected by AArnott
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants