Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rust: Connect to a socket and talk
extern mod std;
use std::{net_tcp,net_ip};
use std::uv;
fn fetch(code: ~str) -> ~[~str] {
let ipaddr = net_ip::v4::parse_addr("");
let iotask = uv::global_loop::get();
let connect_result = net_tcp::connect(ipaddr, 80, &iotask);
let sock;
let data_get = fmt!(
"GET /pub/data/observations/metar/decoded/%s.TXT\n HTTP/1.0",
// On 0.6 master branch, this line above should be:
// code.to_upper().to_str()
let data_headers = "Host:\n\n";
match connect_result {
Ok(socket) => { sock = net_tcp::socket_buf(socket); }
Err(e) => { println(fmt!("%?", e)); return ~[]; }
return sock.read_lines();
fn main() {
let contents = fetch(~"CYVR");
println(fmt!("%?", contents));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.