mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-12 18:38:43 -06:00
oops
This commit is contained in:
parent
7ecc4d5c24
commit
907e3164d7
|
@ -64,7 +64,7 @@ pub struct Client<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||||
}
|
}
|
||||||
impl<S, R> Client<S, R> where S: Encode + Decode, R: Encode + Decode {
|
impl<S, R> Client<S, R> where S: Encode + Decode, R: Encode + Decode {
|
||||||
pub fn new(addr: SocketAddr, config: ClientConfig) -> Result<Self> {
|
pub fn new(addr: SocketAddr, config: ClientConfig) -> Result<Self> {
|
||||||
let bind_addr: SocketAddr = "127.0.0.1:0".parse().unwrap();
|
let bind_addr: SocketAddr = "0.0.0.0:0".parse().unwrap();
|
||||||
let socket = UdpSocket::bind(bind_addr)?;
|
let socket = UdpSocket::bind(bind_addr)?;
|
||||||
socket.set_nonblocking(true)?;
|
socket.set_nonblocking(true)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
@ -16,7 +16,7 @@ const STC_MSG: StcMessage = 0xdead_beef_cafe_face;
|
||||||
fn test_connection() {
|
fn test_connection() {
|
||||||
//Init logging
|
//Init logging
|
||||||
kubi_logging::init();
|
kubi_logging::init();
|
||||||
|
|
||||||
//Create server and client
|
//Create server and client
|
||||||
let mut server: Server<StcMessage, CtsMessage> = Server::bind(
|
let mut server: Server<StcMessage, CtsMessage> = Server::bind(
|
||||||
TEST_ADDR.parse().expect("Invalid TEST_ADDR"),
|
TEST_ADDR.parse().expect("Invalid TEST_ADDR"),
|
||||||
|
@ -31,13 +31,13 @@ fn test_connection() {
|
||||||
let server_handle = thread::spawn(move || {
|
let server_handle = thread::spawn(move || {
|
||||||
let mut message_received = false;
|
let mut message_received = false;
|
||||||
loop {
|
loop {
|
||||||
server.update();
|
server.update().unwrap();
|
||||||
let events: Vec<_> = server.process_events().collect();
|
let events: Vec<_> = server.process_events().collect();
|
||||||
for event in events {
|
for event in events {
|
||||||
match event {
|
match event {
|
||||||
ServerEvent::Connected(id) => {
|
ServerEvent::Connected(id) => {
|
||||||
assert_eq!(id.get(), 1, "Unexpected client id");
|
assert_eq!(id.get(), 1, "Unexpected client id");
|
||||||
server.send_message(id, STC_MSG);
|
server.send_message(id, STC_MSG).unwrap();
|
||||||
},
|
},
|
||||||
ServerEvent::Disconnected(id) => {
|
ServerEvent::Disconnected(id) => {
|
||||||
assert!(message_received, "Client {id} disconnected from the server before sending the message")
|
assert!(message_received, "Client {id} disconnected from the server before sending the message")
|
||||||
|
@ -63,13 +63,13 @@ fn test_connection() {
|
||||||
let client_handle = thread::spawn(move || {
|
let client_handle = thread::spawn(move || {
|
||||||
let mut message_received = false;
|
let mut message_received = false;
|
||||||
loop {
|
loop {
|
||||||
client.update();
|
client.update().unwrap();
|
||||||
let events: Vec<_> = client.process_events().collect();
|
let events: Vec<_> = client.process_events().collect();
|
||||||
for event in events {
|
for event in events {
|
||||||
match event {
|
match event {
|
||||||
ClientEvent::Connected(id) => {
|
ClientEvent::Connected(id) => {
|
||||||
assert_eq!(id.get(), 1, "Unexpected client id");
|
assert_eq!(id.get(), 1, "Unexpected client id");
|
||||||
client.send_message(CTS_MSG);
|
client.send_message(CTS_MSG).unwrap();
|
||||||
},
|
},
|
||||||
ClientEvent::Disconnected(reason) => {
|
ClientEvent::Disconnected(reason) => {
|
||||||
assert!(message_received, "Client lost connection to the server before sending the message with reason: {reason:?}")
|
assert!(message_received, "Client lost connection to the server before sending the message with reason: {reason:?}")
|
||||||
|
|
Loading…
Reference in a new issue