Inspired by your question, I'm now eyeballing what Servo does in the
`rust-http-client` submodulel...
https://github.com/mozilla-servo/rust-http-client


Kevin


On Fri, Aug 2, 2013 at 1:10 AM, Ivan Ristić <[email protected]> wrote:
> I am starting to play with Rust, but I got stuck early on with a trivial
> TCP client example. (There's a few server examples out there, but I
> couldn't find a single working client anywhere. I tried the archives,
> the tests, etc.)
>
> My naive approach sends some data to the server and then attempts to
> read, but socket.read() always times out. I have verified that the
> server is receiving the request and responding to it.
>
> I came across a couple of tickets that suggest that I might be handling
> the event loop incorrectly, but I don't know enough to fix the code.
>
> Your help is appreciated. Thanks.
>
> extern mod extra;
> use extra::net::{ip, tcp};
> use extra::uv;
> use std::str;
>
> fn main() {
>     let ip_addr = ip::v4::parse_addr("204.232.212.130");
>     let iotask = &uv::global_loop::get();
>
>     let r = tcp::connect(ip_addr, 80, iotask);
>     match(r) {
>         Err(err) => {
>                 println(fmt!("Connection failed: %?", err))
>         }
>
>         Ok(socket) => {
>                 let r = socket.write(bytes!("GET / 
> HTTP/1.0\r\n\r\n").to_owned());
>                 if (r.is_err()) {
>                         println(fmt!("Write error: %?", r.get_err()))
>                 } else {
>                     let r = socket.read(2000);
>                     if (r.is_err()) {
>                             println(fmt!("Read error: %?", r.get_err()))
>                     } else {
>                             let bytes = r.get();
>                             println(str::from_bytes(bytes));
>                     }
>             }
>         }
>     }
> }
>
> --
> Ivan
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to