Constructor
new Socket(hostopt, portopt, byteClassopt)
Create new Socket Object. The default byte order is Socket.BIG_ENDIAN. If no arguments are specified, a socket that is initially broken is created. If a valid parameter is specified, try connecting to the specified host and port.
Be careful: It is strongly recommended to use Without parameters The constructor's form, and adds any event listeners and settings such as protocols properties, and then calls the connect method using the host and port arguments. This sequence ensures that all event listeners and other related processes work properly.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
host |
String
|
<optional> |
null | host Server address. |
port |
int
|
<optional> |
0 | port Server port. |
byteClass |
Class
|
<optional> |
null | byteClass The Byte class used to receive and send data. If NULL, the Byte class is used, and the subclass of the Byte class can also be passed in. |
Extends
Member
(static) BIG_ENDIAN :String
- Default Value:
- "bigEndian"
(static) LITTLE_ENDIAN :String
- Default Value:
- "littleEndian"
connected :Boolean
disableInput :Boolean
endian :String
The host byte order, are two different sequence of CPU stored data, including little endian and big endian.
LITTLE_ENDIAN: small endian, low address, low address, high address, high storage value.
BIG_ENDIAN: big endian addresses low storage value high, high value and low storage.
input :Object
output :Object
protocols :Object
Sub protocol name. An array of protocol names, strings, or strings consisting of multiple sub protocol name strings. Assignment must be made before calling connect or connectByUrl, otherwise invalid.
Once specified, the connection can be established only if the server selects one of the sub protocols, otherwise failure to establish and distribute Event.ERROR events.
Methods
cleanSocket()
close()
connect(host, port)
Connect to the specified host and port.
A successful connection dispatches the Event.OPEN event; the connection failure dispatches the Event.ERROR event; the connection is closed to distribute the Event.CLOSE event; data received dispatches the Event.MESSAGE event; in addition to the Event.MESSAGE parameters for the event data, other event parameters are native HTML DOM Event object.
Parameters:
Name | Type | Description |
---|---|---|
host |
String
|
Server address. |
port |
int
|
Server port. |
connectByUrl(url要连接的服务端)
连接到指定的服务端 WebSocket URL。 URL 类似 ws://
A successful connection dispatches the Event.OPEN event; the connection failure dispatches the Event.ERROR event; the connection is closed to distribute the Event.CLOSE event; data received dispatches the Event.MESSAGE event; in addition to the Event.MESSAGE parameters for the event data, other event parameters are native HTML DOM Event object.
Parameters:
Name | Type | Description |
---|---|---|
url要连接的服务端 |
String
|
WebSocket URL。 URL 类似 ws:// Yourdomain:port. |
event(type, dataopt) → {Boolean}
- Inherited From:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String
|
Event type. | ||
data |
Object
|
<optional> |
null | data (optional) callback data. Be careful: If you need to pass multiple parameters, P1, P2, P3, you can use the array structure, such as: [p1,p2,p3,...] If you need to call a single parameter P, and P is an array, you need to use a structure such as: [p] Other single parameters, P, can be passed directly to the parameter P. |
Returns:
- Type:
-
Boolean
flush()
hasListener(type) → {Boolean}
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
type |
String
|
Event type. |
Returns:
- Type:
-
Boolean
isMouseEvent(type) → {Boolean}
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
type |
String
|
Event type. |
Returns:
- Type:
-
Boolean
off(type, caller, listener, onceOnly) → {EventDispatcher}
- Inherited From:
Parameters:
Name | Type | Description |
---|---|---|
type |
String
|
Event type. |
caller |
Object
|
The domain of the event listener function. |
listener |
function
|
Event listener function. |
onceOnly |
Boolean
|
(optional) if the value is true, only the listeners added by the once method are removed. |
offAll(typeopt) → {EventDispatcher}
- Inherited From:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String
|
<optional> |
null | type (optional) event type. If the value is null, all types of listeners for this object are removed. |
on(type, caller, listener, argsopt) → {EventDispatcher}
- Inherited From:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String
|
Event type. | ||
caller |
Object
|
The domain of the event listener function. | ||
listener |
function
|
Event listener function. | ||
args |
Array
|
<optional> |
null | args Optional callback parameters for the event listener function. |
once(type, caller, listener, argsopt) → {EventDispatcher}
- Inherited From:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String
|
Event type. | ||
caller |
Object
|
The domain of the event listener function. | ||
listener |
function
|
Event listener function. | ||
args |
Array
|
<optional> |
null | args Optional callback parameters for the event listener function. |
send(data)
Parameters:
Name | Type | Description |
---|---|---|
data |
Object
|
The data to be sent can be either String or ArrayBuffer. |
Event
close
- See:
-
- events.Event
error
- See:
-
- events.Event
message
- See:
-
- events.Event
open
- See:
-
- events.Event