CFLib.org – Common Function Library Project

sendUDP(host, port, message)

Last updated August 5, 2011

Version: 1 | Requires: ColdFusion 5 | Library: NetLib

 
Rated 0 time(s). Average Rating: 0

Description:
Sends a UDP packet.

Return Values:
Returns nothing.

Example:

view plain print about
<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:

view plain print about
<!---
 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, August 5, 2011 
--->

<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] = ascMid(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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Robby Lansaw Robby Lansaw added
getComponentProp...
3 day(s) ago

Dave Anderson Dave Anderson added
iniToStruct
25 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
25 day(s) ago

Richard Richard added
dice
27 day(s) ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson