跳到主要内容

bn.connectSocket

connectSocket(options): SocketTask

description Create a WebSocket Connect.

example

 bn.connectSocket({
url: 'wss://binance.com'
header:{
'content-type': 'application/json'
},
protocols: ['protocol1']
})

Parameters

NameType
optionsConnectSocketOption

Returns

SocketTask

Interface: ConnectSocketOption

NameTypeDescription
urlstringDeveloper Server wss Interface address
header?anyHTTP Header,Header Can not be set Refer
perMessageDeflate?booleanEnable compression expansion
protocols?string[]Subprotocol array
tcpNoDelay?booleanestablish TCP At the time of the connection. TCP_NODELAY Set up
timeout?numberTimeout in milliseconds
success?(res): void
complete?(res): void
fail?(res): void

success

Optional success(res): void

Parameters

NameType
resGeneralCallbackResult

Returns

void


complete

Optional complete(res): void

Parameters

NameType
resGeneralCallbackResult

Returns

void


fail

Optional fail(res): void

Parameters

NameType
resGeneralCallbackResult

Returns

void

Interface: GeneralCallbackResult

NameTypeDescription
errMsgstring

Interface: SocketTask

NameTypeDescription
send(args): voidadopt WebSocket Connect to send data
close(args): voidStop WebSocket Connect
onOpen(cb): voidto monitor WebSocket Connection Open Event
onClose(cb): voidto monitor WebSocket Connection Closure Event
onError(cb): voidto monitor WebSocket Error event
onMessage(cb): voidto monitor WebSocket Message event received from server
socketTaskId?string
readyStatenumber
errMsgstring
CONNECTING0
OPEN1
CLOSING2
CLOSED3
_idstring

send

send(args): void

adopt WebSocket Connect to send data

Parameters

NameType
argsObject
args.dataWebSocketData

Returns

void


close

close(args): void

Stop WebSocket Connect

Parameters

NameType
argsOmit<WebSocketCloseOptions, "id">

Returns

void


onOpen

onOpen(cb): void

to monitor WebSocket Connection Open Event

Parameters

NameType
cbOnOpen

Returns

void


onClose

onClose(cb): void

to monitor WebSocket Connection Closure Event

Parameters

NameType
cbOnClose

Returns

void


onError

onError(cb): void

to monitor WebSocket Error event

Parameters

NameType
cbOnError

Returns

void


onMessage

onMessage(cb): void

to monitor WebSocket Message event received from server

Parameters

NameType
cbOnMessage

Returns

void