Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running HttpServer example from documentation leads to weirdness and VM issues #7356

Closed
DartBot opened this issue Dec 12, 2012 · 4 comments
Closed
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-obsolete Closed as the reported issue is no longer relevant type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@DartBot
Copy link

DartBot commented Dec 12, 2012

This issue was originally filed by jjinux...@google.com


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

@DartBot
Copy link
Author

DartBot commented Dec 12, 2012

This comment was originally written by jjinux...@google.com


Dart Editor version 0.2.7_r15699
Dart SDK version 0.2.7.1_r15699

@DartBot
Copy link
Author

DartBot commented Dec 12, 2012

This comment was originally written by jjinux...@google.com


I tried upgrading my Dart Editor, but when I click "Check for Update", it says "Unable to get latest revision".

@DartBot
Copy link
Author

DartBot commented Dec 13, 2012

This comment was originally written by @chrisbu


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.

@iposva-google
Copy link
Contributor

Removed Priority-Medium label.
Added Priority-Unassigned label.

@DartBot DartBot added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. labels Jun 5, 2013
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@iposva-google iposva-google added the closed-obsolete Closed as the reported issue is no longer relevant label May 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. closed-obsolete Closed as the reported issue is no longer relevant type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants