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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson