sendUDP(host, port, message)
Last updated August 5, 2011
Version: 1 | Requires: ColdFusion 5 | Library: NetLib
Description:
Sends a UDP packet.
Return Values:
Returns nothing.
Example:
#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, 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] = 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
Robby Lansaw added
getComponentProp...
3 day(s) ago
Dave Anderson added
iniToStruct
25 day(s) ago
Dave Anderson added
deDupeArray
25 day(s) ago
Richard added
dice
27 day(s) ago
Top Rated
backupDatabase
Rated 5.0, 22 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)
highlightAndCrop
Rated 5.0, 4 time(s)