SocketIOException: Write failed (OS Error: Broken pipe, errno = 32) - WTF? =)

1,178 views
Skip to first unread message

Jakob Dam Jensen

unread,
Jan 3, 2013, 4:12:22 AM1/3/13
to mi...@dartlang.org
So I've started playing around with Dart. I've reached a point where I'm trying to send a HTTP GET requests to another server (from a dart VM app).

I'm using the HttpClient in the dart:io package but I'm getting a SocketIOException when connecting.

  HttpClient client = new HttpClient();
  HttpClientConnection connection = client.openUrl('get', new Uri.fromString("http://localhost:8383/users"));

  connection.onResponse = (HttpClientResponse response){
    List<int> content = response.inputStream.read(response.contentLength);
    String contentString = new String.fromCharCodes(content);
    print(contentString);
  };

  connection.onError = (Exception e){
    print("error");
    print(e);
  };

I've looked into the docs and the source code for HttpClient and SocketIOException - but I can't find any explanation for this type of error. Also I've tried accessing the url from a browser and it works fine.


Any suggestions?


Thanks..


William Hesse

unread,
Jan 3, 2013, 6:59:45 AM1/3/13
to General Dart Discussion
Could the problem be the capitalization of 'get'? I think servers
will only accept uppercase 'GET'.

On Thu, Jan 3, 2013 at 10:12 AM, Jakob Dam Jensen
<ja...@nopointlessapps.com> wrote:
> HttpClient client = new HttpClient();
> HttpClientConnection connection = client.openUrl('get', new
> Uri.fromString("http://localhost:8383/users"));
>
> connection.onResponse = (HttpClientResponse response){
> List<int> content = response.inputStream.read(response.contentLength);
> String contentString = new String.fromCharCodes(content);
> print(contentString);
> };
>
> connection.onError = (Exception e){
> print("error");
> print(e);
> };



--
William Hesse

Jakob Dam Jensen

unread,
Jan 3, 2013, 7:27:01 AM1/3/13
to mi...@dartlang.org
HAHA - You're absolutely right. That was stupid =)

Thanks 

Bob Nystrom

unread,
Jan 3, 2013, 1:41:45 PM1/3/13
to General Dart Discussion
If you're interested, there is also an HTTP package that provides an alternate API for doing HTTP requests. Using that, I believe your code would be:

http.get("http://localhost:8383/users")..then((response) {
  print(response.body);
})..handleException((ex) {
  print("error");
  print(ex);
});

If you want something more Future-based and high-level (though not as comprehensive and full-featured as dart:io), you may want to take a look at that. It's what we use internally in Pub. 

Cheers,

- bob

Jakob Dam Jensen

unread,
Jan 4, 2013, 12:49:29 AM1/4/13
to mi...@dartlang.org
Great tip - thanks...
Reply all
Reply to author
Forward
0 new messages