The socket.send() method is an inbuilt application programming interface of class Socket within dgram module which is used to send the message from one socket to another socket.
socket.send(msg[, offset, length][, port][, address][, callback])
Parameters: This method takes the following parameter:
- msg: Message to be sent.
- offset: Offset in the buffer where the message starts.
- length: Number of bytes in the message.
- port: Destination port.
- address: Destination host name or IP address.
- callback: Called when the message has been sent.
Return Value: This method does not return any value.
Example 1: Filename: index.js
[ 'message' ] UDP String: Hello
Example 2: Filename: index.js
server listening 0.0.0.0:1234 [ 'message', 'listening' ] message sent UDP String: Hello
Run the index.js file using the following command:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.