| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of vmservice_io; | 5 part of vmservice_io; |
| 6 | 6 |
| 7 class WebSocketClient extends Client { | 7 class WebSocketClient extends Client { |
| 8 static const int PARSE_ERROR_CODE = 4000; | 8 static const int PARSE_ERROR_CODE = 4000; |
| 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; | 9 static const int BINARY_MESSAGE_ERROR_CODE = 4001; |
| 10 static const int NOT_MAP_ERROR_CODE = 4002; | 10 static const int NOT_MAP_ERROR_CODE = 4002; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 Map map = super.toJson(); | 74 Map map = super.toJson(); |
| 75 map['type'] = 'HttpRequestClient'; | 75 map['type'] = 'HttpRequestClient'; |
| 76 map['request'] = '$request'; | 76 map['request'] = '$request'; |
| 77 return map; | 77 return map; |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 | 80 |
| 81 class Server { | 81 class Server { |
| 82 static const WEBSOCKET_PATH = '/ws'; | 82 static const WEBSOCKET_PATH = '/ws'; |
| 83 String defaultPath = '/index.html'; | 83 String defaultPath = '/index.html'; |
| 84 final String ip; |
| 84 int port; | 85 int port; |
| 85 | 86 |
| 86 final VMService service; | 87 final VMService service; |
| 87 HttpServer _server; | 88 HttpServer _server; |
| 88 | 89 |
| 89 Server(this.service, this.port); | 90 Server(this.service, this.ip, this.port); |
| 90 | 91 |
| 91 void _requestHandler(HttpRequest request) { | 92 void _requestHandler(HttpRequest request) { |
| 92 // Allow cross origin requests. | 93 // Allow cross origin requests. |
| 93 request.response.headers.add('Access-Control-Allow-Origin', '*'); | 94 request.response.headers.add('Access-Control-Allow-Origin', '*'); |
| 94 | 95 |
| 95 final String path = | 96 final String path = |
| 96 request.uri.path == '/' ? defaultPath : request.uri.path; | 97 request.uri.path == '/' ? defaultPath : request.uri.path; |
| 97 | 98 |
| 98 var resource = Resource.resources[path]; | 99 var resource = Resource.resources[path]; |
| 99 if (resource != null) { | 100 if (resource != null) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 }); | 112 }); |
| 112 return; | 113 return; |
| 113 } | 114 } |
| 114 | 115 |
| 115 var message = new Message.fromUri(request.uri); | 116 var message = new Message.fromUri(request.uri); |
| 116 var client = new HttpRequestClient(request, service); | 117 var client = new HttpRequestClient(request, service); |
| 117 client.onMessage(null, message); | 118 client.onMessage(null, message); |
| 118 } | 119 } |
| 119 | 120 |
| 120 Future startServer() { | 121 Future startServer() { |
| 121 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((s) { | 122 return HttpServer.bind(ip, port).then((s) { |
| 122 // Only display message when port is automatically selected. | 123 // Only display message when port is automatically selected. |
| 123 var display_message = (port == 0); | 124 var display_message = (ip != '127.0.0.1' || port != 8181); |
| 124 // Retrieve port. | 125 // Retrieve port. |
| 125 port = s.port; | 126 port = s.port; |
| 126 _server = s; | 127 _server = s; |
| 127 _server.listen(_requestHandler); | 128 _server.listen(_requestHandler); |
| 128 if (display_message) { | 129 if (display_message) { |
| 129 print('VMService listening on port $port'); | 130 print('VMService listening on $ip:$port'); |
| 130 } | 131 } |
| 131 return s; | 132 return s; |
| 132 }); | 133 }); |
| 133 } | 134 } |
| 134 } | 135 } |
| OLD | NEW |