1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MOJO_SPY_WEBSOCKET_SERVER_H_
6 #define MOJO_SPY_WEBSOCKET_SERVER_H_
8 #include "net/server/http_server.h"
12 class WebSocketServer : public net::HttpServer::Delegate {
14 // Pass 0 in |port| to listen in one available port.
15 explicit WebSocketServer(int port);
16 virtual ~WebSocketServer();
17 // Begin accepting HTTP requests. Must be called from an IO MessageLoop.
19 // Returns the listening port, useful if 0 was passed to the contructor.
20 int port() const { return port_; }
23 // Overridden from net::HttpServer::Delegate.
24 virtual void OnHttpRequest(
26 const net::HttpServerRequestInfo& info) OVERRIDE;
27 virtual void OnWebSocketRequest(
29 const net::HttpServerRequestInfo& info) OVERRIDE;
30 virtual void OnWebSocketMessage(
32 const std::string& data) OVERRIDE;
33 virtual void OnClose(int connection_id) OVERRIDE;
38 scoped_refptr<net::HttpServer> server_;
39 DISALLOW_COPY_AND_ASSIGN(WebSocketServer);
44 #endif // MOJO_SPY_WEBSOCKET_SERVER_H_