An UDP Socket instance. Use IPv4 protocol by default.
Reference
Methods close Closes (Terminates) a UDP Socket instance. After closing, the UDP Socket instance can no longer send messages. Calling UDPSocket.send
will trigger an error event, and the callback function for the message event will not be executed. After the UDPSocket
instance is created, it will be strongly referenced by Native to ensure that it is not collected by GC. After calling UDPSocket.close
, the strong reference to it will be removed, and the UDPSocket instance will follow the GC rules.
Reference
API Support API WeChat Mini-Program H5 React Native UDPSocket.close ✔️
offClose Un-listens on the disabling event.
Reference
( callback : OffCloseCallback ) => void
Copy Property Type Description callback OffCloseCallback
The callback function for the disabling event.
API Support API WeChat Mini-Program H5 React Native UDPSocket.offClose ✔️
offError Un-listens on the error event.
Reference
( callback : OffErrorCallback ) => void
Copy Property Type Description callback OffErrorCallback
The callback function for the error event.
API Support API WeChat Mini-Program H5 React Native UDPSocket.offError ✔️
offListening Un-listens on the event of starting listening on data packet messages.
Reference
( callback : ( res : CallbackResult ) => void ) => void
Copy Property Type Description callback (res: CallbackResult) => void
The callback function for the event of starting listening on data packet messages.
API Support API WeChat Mini-Program H5 React Native UDPSocket.offListening ✔️
offMessage Un-listens on the event of receiving messages.
Reference
( callback : ( res : CallbackResult ) => void ) => void
Copy Property Type Description callback (res: CallbackResult) => void
The callback function for the event of receiving messages.
API Support API WeChat Mini-Program H5 React Native UDPSocket.offMessage ✔️
onClose Listens on the disabling event.
Reference
( callback : OnCloseCallback ) => void
Copy Property Type Description callback OnCloseCallback
The callback function for the disabling event.
API Support API WeChat Mini-Program H5 React Native UDPSocket.onClose ✔️
onError Listens on the error event.
Reference
( callback : OnErrorCallback ) => void
Copy Property Type Description callback OnErrorCallback
The callback function for the error event.
API Support API WeChat Mini-Program H5 React Native UDPSocket.onError ✔️
onListening Listens on the event of starting listening on data packet messages.
Reference
( callback : ( res : CallbackResult ) => void ) => void
Copy Property Type Description callback (res: CallbackResult) => void
The callback function for the event of starting listening on data packet messages.
API Support API WeChat Mini-Program H5 React Native UDPSocket.onListening ✔️
onMessage Listens on the event of receiving messages.
Reference
( callback : OnMessageCallback ) => void
Copy Property Type Description callback OnMessageCallback
The callback function for the event of receiving messages.
API Support API WeChat Mini-Program H5 React Native UDPSocket.onMessage ✔️
send Sends messages to the specified IP and port.
Reference
( option : SendOption ) => void
Copy Property Type option SendOption
API Support API WeChat Mini-Program H5 React Native UDPSocket.send ✔️
bind Binds an available port randomly assigned by the system.
Reference
( port : number ) => number
Copy Property Type Description port number
Bound port number
API Support API WeChat Mini-Program H5 React Native UDPSocket.bind ✔️
Parameters OffCloseCallback The callback function for the disabling event.
( res : CallbackResult ) => void
Copy Property Type res CallbackResult
OffErrorCallback The callback function for the error event.
( res : CallbackResult ) => void
Copy Property Type res CallbackResult
OnCloseCallback The callback function for the disabling event.
( res : CallbackResult ) => void
Copy Property Type res CallbackResult
OnErrorCallback The callback function for the error event.
( result : OnErrorCallbackResult ) => void
Copy Property Type result OnErrorCallbackResult
OnMessageCallback The callback function for the event of receiving messages.
( result : OnMessageCallbackResult ) => void
Copy Property Type result OnMessageCallbackResult
OnErrorCallbackResult Property Type Description errMsg string
错误信息
OnMessageCallbackResult Property Type Description message ArrayBuffer
Received messages remoteInfo RemoteInfo
Structured information of message sources
RemoteInfo remoteInfo is composed as follows
Property Type Description address string
The address of the socket sending the message family string
The protocol family used, IPv4 or IPv6 port number
Port number size number
The message size, in bytes
SendOption Property Type Required Description data string | ArrayBuffer
Yes The data to be sent complete (res: CallbackResult) => void
No The callback function used when the API call completed (always executed whether the call succeeds or fails) fail (res: CallbackResult) => void
No The callback function for a failed API call success (res: CallbackResult) => void
No The callback function for a successful API call
API Support API WeChat Mini-Program H5 React Native UDPSocket.close ✔️ UDPSocket.offClose ✔️ UDPSocket.offError ✔️ UDPSocket.offListening ✔️ UDPSocket.offMessage ✔️ UDPSocket.onClose ✔️ UDPSocket.onError ✔️ UDPSocket.onListening ✔️ UDPSocket.onMessage ✔️ UDPSocket.send ✔️ UDPSocket.bind ✔️