Skip to content

websocket-okcoin 為Html+JavaScript+CSS寫的網頁,用來練習的websockt api網頁

Notifications You must be signed in to change notification settings

cubshuang/websocket-okcoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

websocket-okcoin

websocket-okcoin 為Html+JavaScript+CSS寫的網頁,用來練習的websockt api網頁

WebSocket 建立一個WebSocket物件

var ws = new WebSocket('ws://url');

readyState WebSocket物件目前狀態,共四種:

CONNECTING:值為0,表示正在連線中。

OPEN:值為1,表示連線成功,可以進行通訊作業。

CLOSING:值為2,表示連線正在關閉。

CLOSED:值為3,表示連線已關閉,或連線失敗。

onopen 連線成功

ws.onmessage = function(event) {
  console.log('websocket is opened');
};

send 傳資料給伺服器

ws.send('my message');

onmessage 從伺服器收到回傳的訊息

ws.onmessage = function(event) {
  console.log('recive message');
};

onclose 關閉連線

ws.onmessage = function(event) {
  console.log('websocket is closed');
};

onerror 發生錯誤

ws.onerror = function(event) {
  console.log('websocket error');
};

Demo

Reference

About

websocket-okcoin 為Html+JavaScript+CSS寫的網頁,用來練習的websockt api網頁

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published