Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:html
  3. WebSocket class
WebSocket
description

WebSocket class

Use the WebSocket interface to connect to a WebSocket,and to send and receive data on that WebSocket.

To use a WebSocket in your web app, first create a WebSocket object,passing the WebSocket URL as an argument to the constructor.

var webSocket = new WebSocket('ws://127.0.0.1:1337/ws');

To send data on the WebSocket, use thesend method.

if (webSocket != null && webSocket.readyState == WebSocket.OPEN) {  webSocket.send(data);} else {  print('WebSocket not connected, message $data not sent');}

To receive data on the WebSocket, register a listener for message events.

webSocket.onMessage.listen((MessageEvent e) {  receivedData(e.data);});

The message event handler receives aMessageEvent objectas its sole argument.You can also define open, close, and error handlers,as specified byEvents.

For more information, see theWebSocketssection of the library tour andIntroducing WebSockets,an HTML5Rocks.com tutorial.

Inheritance
Annotations
  • @SupportedBrowser.new(SupportedBrowser.CHROME)
  • @SupportedBrowser.new(SupportedBrowser.FIREFOX)
  • @SupportedBrowser.new(SupportedBrowser.IE, '10')
  • @SupportedBrowser.new(SupportedBrowser.SAFARI)
  • @Unstable.new()
  • @Native.new("WebSocket")

Constructors

WebSocket(Stringurl, [Object?protocols])
factory

Properties

binaryTypeString?
getter/setter pair
bufferedAmountint?
no setter
extensionsString?
no setter
hashCodeint
The hash code for this object.
no setterinherited
onEvents
This is an ease-of-use accessor for event streams which should only beused when an explicit accessor is not available.
no setterinherited
onCloseStream<CloseEvent>
Stream ofclose events handled by thisWebSocket.
no setter
onErrorStream<Event>
Stream oferror events handled by thisWebSocket.
no setter
onMessageStream<MessageEvent>
Stream ofmessage events handled by thisWebSocket.
no setter
onOpenStream<Event>
Stream ofopen events handled by thisWebSocket.
no setter
protocolString?
no setter
readyStateint
no setter
runtimeTypeType
A representation of the runtime type of the object.
no setterinherited
urlString?
no setter

Methods

addEventListener(Stringtype,EventListener?listener, [bool?useCapture])→ void
inherited
close([int?code,String?reason])→ void
dispatchEvent(Eventevent)bool
inherited
noSuchMethod(Invocationinvocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeEventListener(Stringtype,EventListener?listener, [bool?useCapture])→ void
inherited
send(dynamicdata)→ void
Transmit data to the server over this connection.
sendBlob(Blobdata)→ void
Transmit data to the server over this connection.
sendByteBuffer(ByteBufferdata)→ void
Transmit data to the server over this connection.
sendString(Stringdata)→ void
Transmit data to the server over this connection.
sendTypedData(TypedDatadata)→ void
Transmit data to the server over this connection.
toString()String
A string representation of this object.
inherited

Operators

operator ==(Objectother)bool
The equality operator.
inherited

Static Properties

supportedbool
Checks if this type is supported on the current platform.
no setter

Constants

CLOSED→ constint
closeEvent→ constEventStreamProvider<CloseEvent>
Static factory designed to exposeclose events to eventhandlers that are not necessarily instances ofWebSocket.
CLOSING→ constint
CONNECTING→ constint
errorEvent→ constEventStreamProvider<Event>
Static factory designed to exposeerror events to eventhandlers that are not necessarily instances ofWebSocket.
messageEvent→ constEventStreamProvider<MessageEvent>
Static factory designed to exposemessage events to eventhandlers that are not necessarily instances ofWebSocket.
OPEN→ constint
openEvent→ constEventStreamProvider<Event>
Static factory designed to exposeopen events to eventhandlers that are not necessarily instances ofWebSocket.
  1. Dart
  2. dart:html
  3. WebSocket class
dart:html library

[8]ページ先頭

©2009-2025 Movatter.jp