WebSocket.fromUpgradedSocket constructor

WebSocket.fromUpgradedSocket(Socket socket, { String protocol, bool serverSide, CompressionOptions compression: CompressionOptions.compressionDefault })

Creates a WebSocket from an already-upgraded socket.

The initial WebSocket handshake must have occurred prior to this call. A WebSocket client can automatically perform the handshake using WebSocket.connect, while a server can do so using WebSocketTransformer.upgrade. To manually upgrade an HttpRequest, HttpResponse.detachSocket may be called.

protocol should be the protocol negotiated by this handshake, if any.

serverSide must be passed explicitly. If it's false, the WebSocket will act as the client and mask the messages it sends. If it's true, it will act as the server and will not mask its messages.

If compression is provided, the WebSocket created will be configured to negotiate with the specified CompressionOptions. If none is specified then the WebSocket will be created with the default CompressionOptions.

Implementation

factory WebSocket.fromUpgradedSocket(Socket socket,
    {String protocol,
    bool serverSide,
    CompressionOptions compression: CompressionOptions.compressionDefault}) {
  if (serverSide == null) {
    throw new ArgumentError("The serverSide argument must be passed "
        "explicitly to WebSocket.fromUpgradedSocket.");
  }
  return new _WebSocketImpl._fromSocket(
      socket, protocol, compression, serverSide);
}