first working version
This commit is contained in:
commit
db8370e642
8 changed files with 240 additions and 0 deletions
22
src/connection.rs
Normal file
22
src/connection.rs
Normal file
|
@ -0,0 +1,22 @@
|
|||
use std::net::{ToSocketAddrs, UdpSocket};
|
||||
use crate::{Command, Packet};
|
||||
|
||||
pub struct Connection {
|
||||
socket: UdpSocket,
|
||||
}
|
||||
|
||||
impl Connection {
|
||||
/// Open a new UDP socket and create a display instance
|
||||
pub fn open(addr: impl ToSocketAddrs) -> std::io::Result<Self> {
|
||||
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||
socket.connect(addr)?;
|
||||
Ok(Self { socket })
|
||||
}
|
||||
|
||||
/// Send a command to the display
|
||||
pub fn send(&self, command: Command) -> std::io::Result<()> {
|
||||
let packet: Packet = command.into();
|
||||
self.socket.send(&packet)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue