Guest User

Untitled

a guest
Feb 24th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. extern crate rand;
  2.  
  3. use rand::Rng;
  4. use std::env;
  5. use std::io::prelude::*;
  6. use std::net::{TcpStream, Shutdown};
  7. use std::time::Duration;
  8.  
  9. fn main() {
  10. let endpoint = env::var("OPC_ENDPOINT")
  11. .unwrap_or(String::from("127.0.0.1:7890"));
  12. let mut stream = TcpStream::connect(endpoint).unwrap();
  13. stream.shutdown(Shutdown::Read).unwrap(); // Not a great listener...
  14. stream.set_nodelay(true).unwrap();
  15. let mut rng = rand::thread_rng();
  16.  
  17. loop {
  18. let mut message = vec![0u8; 4+(512*3)];
  19. // Command and channel both 0.
  20. message[2] = ((512u16*3) >> 8) as u8; // Length high byte
  21. message[3] = ((512u16*3) & 255) as u8; // Length low byte
  22.  
  23. for i in 0..(512*3) {
  24. message[i+4] = rng.gen();
  25. }
  26.  
  27. stream.write_all(&message).unwrap();
  28.  
  29. std::thread::sleep(Duration::from_millis(1000));
  30. }
  31. }
Add Comment
Please, Sign In to add comment