Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2015 00:20
Show Gist options
  • Save anonymous/ed1e2e9ffade7b7130a4 to your computer and use it in GitHub Desktop.
Save anonymous/ed1e2e9ffade7b7130a4 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
#![allow(dead_code)]
#![allow(unused_variables)]
use std::io::prelude::*;
use std::net::*;
macro_rules! nada {
() => { unsafe { std::mem::uninitialized() } }
}
#[derive(Debug)]
struct Konnection {
hp : String,
cred : String,
sock : TcpStream,
}
fn konnect( hostport : &str, name : &str, passwd : &str ) -> Konnection {
let mut k : Konnection = nada!();
let mut cred = name.to_string();
cred.push( ':' );
cred.push_str( passwd );
k.cred = cred;
let hp = hostport.to_string();
k.hp = hp;
let mut msg = k.cred.into_bytes();
msg.push_all( "\x03\x00".as_bytes() );
let mut sock = TcpStream::connect( hostport ).unwrap();
println!( "sock {:?}", sock );
let wrote = sock.write_all( &mut msg );
println!( "msg {:?}", msg );
println!( "wrote {:?}", wrote );
k.sock = sock;
return k;
}
fn main() {
let kk = konnect( "localhost:5001", "jason", "" );
// let mut s = kk.sock;
// let mut s = TcpStream::connect( "localhost:5001" ).unwrap();
// println!("kk.s {:?}", s);
// let login_msg = ['j' as u8, 3, 0 ];
// let login_msg = "j\x03\x00".as_bytes();
// let written = s.write_all( &login_msg ).unwrap();
// println!( "{:?}", login_msg );
// println!( "{:?}", written );
// let mut login_resp = [0u8;2];
// let read = s.read( &mut login_resp ).unwrap();
// println!( "{:?}", read );
// println!( "{:?}", login_resp );
println!("done");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment