My favorites | Sign in
Project Home Wiki Issues Source Code Search
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 7356: Running HttpServer example from documentation leads to weirdness and VM issues
2 people starred this issue and may be notified of changes. Back to list
Status:  Triaged
Owner:  ----


Sign in to add a comment
 
Reported by jji...@google.com, Dec 12, 2012
I went (http://www.dartlang.org/articles/io/) to get this example:

import 'dart:io';

_send404(HttpResponse response) {
  response.statusCode = HttpStatus.NOT_FOUND;
  response.outputStream.close();
}

startServer(String basePath) {
  var server = new HttpServer();
  server.listen('127.0.0.1', 8080);
  server.defaultRequestHandler = (HttpRequest request, HttpResponse response) {
    final String path = request.path == '/' ? '/index.html' : request.path;
    final File file = new File('${basePath}${path}');
    file.exists().then((bool found) {
      if (found) {
        file.fullPath().then((String fullPath) {
          if (!fullPath.startsWith(basePath)) {
            _send404(response);
          } else {
            file.openInputStream().pipe(response.outputStream);
          }
        });
      } else {
        _send404(response);
      }
    });
  };
}

main() {
  // Compute base path for the request based on the location of the
  // script and then start the server.
  File script = new File(new Options().script);
  script.directory().then((Directory d) {
    startServer(d.path);
  });
}

When I run the code, it looks like it's working, but it doesn't actually listen on port 8080. It seems to just do nothing. When I try to set a breakpoint on the first line of the startServer function, the server output says:

dart --enable-checked-mode bin/server.dart

./vm/object.h:3146: error: Handle check failed: saw Function 'StackOverflowError.': constructor const. expected Instance

Dec 12, 2012
#1 jji...@google.com
Dart Editor version 0.2.7_r15699
Dart SDK version 0.2.7.1_r15699
Dec 12, 2012
#2 jji...@google.com
I tried upgrading my Dart Editor, but when I click "Check for Update", it says "Unable to get latest revision". 
Dec 12, 2012
Project Member #3 chrisbuc...@gmail.com
I've pasted a working version of this code on stack overflow in answer to another question:

http://stackoverflow.com/questions/13843362/client-server-in-dart-programming-language/13851758#13851758

The best approach might be to start with that and add print() statements to aid debugging to add the command line arguments and 404 handler.

Jun 5, 2013
Project Member #4 iposva@google.com
(No comment was entered for this change.)
Labels: -Priority-Medium Priority-Unassigned
Sign in to add a comment

Powered by Google Project Hosting