# UDPSocket
Start from base library version 2.7.0. Please remaining backward compatible.
One UDP Socket Instance, by default IPv4 Protocol.
# method
# number UDPSocket.bind(number port)
Bind a system randomly assigned available port or bind a specified port number
# UDPSocket.setTTL(number ttl)
Set up IP_TTL Socket option to set a IP Maximum number of hops allowed for packet transmission
# UDPSocket.send(Object object)
To the specified IP and port Send a message. Base library 2.9.0 Support Broadcast (The specified address is 255.255.255.255)。
# UDPSocket.connect(Object object)
Preconnect to the specified IP and Port, you need to cooperate. write Methods used together
# UDPSocket.write()
Usage and send Method is the same if the connect With send No difference (note that even if the connect You also need to fill in the address and port parameters for this interface.
# UDPSocket.close()
Stop UDP Socket Instance, equivalent to destruction. After the shutdown, UDP Socket Instance can no longer send messages, and each time the UDPSocket.send
Will trigger an error event, and message The event callback function also does not execute again. in UDPSocket
Instance will be created by the Native Strong references, ensuring that they are not GC。 in UDPSocket.close
Removes a strong reference to it, and lets the UDPSocket Instance compliance GC。
# UDPSocket.onClose(function callback)
Listen Close Event
# UDPSocket.offClose(function callback)
Unlisten Close Event
# UDPSocket.onError(function callback)
Listen for error events
# UDPSocket.offError(function callback)
Unlisten Error Event
# UDPSocket.onListening(function callback)
Listen to start listening for packet messages
# UDPSocket.offListening(function callback)
The event that starts listening for packet messages
# UDPSocket.onMessage(function callback)
Listen to events that receive messages
# UDPSocket.offMessage(function callback)
Unlisten for events that receive messages
# error
Error code | Error message | Introductions |
---|---|---|
-1 | System error | |
-2 | Socket interface error | |
-3 | Send failed, no interface permissions | |
1 | Send failed, parameter error, address illegal | |
2 | Send failed, parameter error, port illegal |