CFLib.org – Common Function Library Project

sendUDP(host, port, message)

Last updated July 31, 2013

author

GaoChangwei

Version: 1 | Requires: CF5 | Library: NetLib

Description:
Sends a UDP packet.

Return Values:
Returns nothing.

Example:

<cfoutput>
#sendUDP('192.168.1.123','90','I will be there')#
</cfoutput>

Parameters:

Name Description Required
host Host to send the UDP Yes
port Port to send the UDP Yes
message The message to transmit Yes

Full UDF Source:

<!---
 Sends a UDP packet.
 
 @param host      Host to send the UDP (Required)
 @param port      Port to send the UDP (Required)
 @param message      The message to transmit (Required)
 @return Returns nothing. 
 @author GaoChangwei (coldfusion.jquery@gmail.com) 
 @version 1, July 31, 2013 
--->
<cffunction name="sendUDP" access="private" returntype="string" output="false">
    <cfargument name="host" type="string" required="yes" hint="Host to send the UDP">
    <cfargument name="port" type="numeric" required="yes" hint="Port to send the UDP">
    <cfargument name="message" type="string" required="yes"  hint="The message to transmit">

    <cfset var text = arguments.message />
    <cfset var msg = arraynew(1) />
    
    <cfset var i = 0>
    <cfloop index="i" from="1" to="#len(text)#">
        <cfset msg[i] = asc( Mid(text, i, 1) ) />
    </cfloop>
    <!--- Get the internet address of the specified host --->
    <cfset address = createObject("java", "java.net.InetAddress").getByName(arguments.host) />
    
    <!--- Initialize a datagram packet with data and address --->
    <cfset packet = createObject("java", "java.net.DatagramPacket").init( javacast("byte[]",msg), 
                                                                          javacast("int",arrayLen(msg)), 
                                                                          address, 
                                                                          javacast("int",arguments.port)) />
                                                                          
    <!--- Create a datagram socket, send the packet through it, close it. --->
    <cfset dsocket = createObject("java", "java.net.DatagramSocket") />    
    <cfset dsocket.send(packet) />
    <cfset dsocket.close() />

</cffunction>

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson