blob: 65a1203a58bde18f4d31c9545b64fe2b2247f105 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::io::{Read as _, Write as _};
const BUS_NAME: &str = "test-bus";
const CLIENT_NAME: &str = "client";
const SERVER_NAME: &str = "server";
const REQUEST: &str = "hello from client";
const RESPONSE: &str = "hello from server";
async fn connect_to_server() {
netemul_sync::Bus::subscribe(BUS_NAME, CLIENT_NAME)
.expect("subscribe to bus")
.expect("wait for server to join bus");
let mut stream = std::net::TcpStream::connect("").expect("connect to server");
let request = REQUEST.as_bytes();
assert_eq!(stream.write(request).expect("write to socket"), request.len());
stream.flush().expect("flush stream");
let mut buffer = [0; 512];
let read = buffer).expect("read from socket");
let response = String::from_utf8_lossy(&buffer[]);
assert_eq!(response, RESPONSE, "got unexpected response from server: {}", response);