esc_pos_lib/
network.rs

1use std::net::TcpStream;
2use std::io::prelude::*;
3
4///Establishes a tcpsocket with a printer.
5///Sends the message in the Vec<u8>
6pub fn send_message(msg: &Vec<u8>, mut address: String, port: u32) -> Result<(), String> {
7    
8    address.push_str(":");
9    address.push_str(&port.to_string());
10    let mut stream = match TcpStream::connect(address) {
11        Ok(stream) => stream,
12        Err(e) => return Err(e.to_string()),
13    };
14    match stream.write(&msg[0..]) {
15        Ok(_) => Ok(()),
16        Err(e) => Err(e.to_string()),
17    }
18}