2023-12-26|閱讀時間 ‧ 約 1 分鐘

[Flutter]WebSockets

這邊會使用WebSocketChannel去與http://www.websocket.org做連線。


連線

final channel = IOWebSocketChannel.connect('wss://echo.websocket.events');


接收

StreamBuilder(
stream: widget.channel.stream,
builder: (context, snapshot) {
//do something​
},
);


發送

channel.sink.add('Hello!');


關閉連線

channel.sink.close();


分享至
成為作者繼續創作的動力吧!
APP程式設計相關的內容,包含:原生與跨平台。
從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

發表回應

成為會員 後即可發表留言
© 2024 vocus All rights reserved.