mirror of
https://github.com/AsamK/signal-cli
synced 2025-08-30 19:10:38 +00:00
parent
edbf803a98
commit
8037fb2d66
10 changed files with 928 additions and 521 deletions
21
client/src/transports/tcp.rs
Normal file
21
client/src/transports/tcp.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use futures_util::stream::StreamExt;
|
||||
use jsonrpsee::core::client::{TransportReceiverT, TransportSenderT};
|
||||
use jsonrpsee::core::Error;
|
||||
use tokio::net::{TcpStream, ToSocketAddrs};
|
||||
use tokio_util::codec::Decoder;
|
||||
|
||||
use super::stream_codec::StreamCodec;
|
||||
use super::{Receiver, Sender};
|
||||
|
||||
/// Connect to a JSON-RPC TCP server.
|
||||
pub async fn connect(
|
||||
socket: impl ToSocketAddrs,
|
||||
) -> Result<(impl TransportSenderT + Send, impl TransportReceiverT + Send), Error> {
|
||||
let connection = TcpStream::connect(socket).await?;
|
||||
let (sink, stream) = StreamCodec::stream_incoming().framed(connection).split();
|
||||
|
||||
let sender = Sender { inner: sink };
|
||||
let receiver = Receiver { inner: stream };
|
||||
|
||||
Ok((sender, receiver))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue