Skip to content

Latest commit

 

History

History
23 lines (19 loc) · 654 Bytes

WebSocketConnect.md

File metadata and controls

23 lines (19 loc) · 654 Bytes

WebSocket: Establishing a Connection and Handling Failure

To establish a WebSocket connection, use the static connect method - it returns a Future that eventually resolves with a transport.WebSocket instance.

var uri = Uri.parse('ws://echo.websocket.org');
var webSocket = await transport.WebSocket.connect(uri);

The connect() method will throw a transport.WebSocketException if a connection cannot be established.

var uri = Uri.parse('ws://echo.websocket.org');
transport.WebSocket webSocket;
try {
  webSocket = await transport.WebSocket.connect(uri);
} on transport.WebSocketException {
  // Handle failure.
}