SendTo

SendTo is used to send data to the current open socket over a UDP Connection.

Syntax

SendTo (ip, port, data, [SizeInBytes])

Returns

The actual amount of bytes sent.

More Information

The SendTo function can only be used with an open Socket object that was opened on a UDP connect, in order to send data over a TCP Connection please check the Send function described earlier on in the document.

The SendTo function accepts an optional parameter (SizeInBytes) which specifies how much of the buffer which was passed to data field will actually be sent. If this optional parameter is omitted, then the size is automatically calculated.

Example

This script connects with a DNSA database used by TCP/IP networks that enables the translation of hostnames into IP numbers and to provide other domain related information. server specified by the IP variable and runs a query for www.gfi.com and than displays the result:

Function Main

Dim SocketObject As Object

Dim ip As String

Dim port As String

Dim rawdata As Variant

Dim Response As Variant

Ip = "172.16.130.40"

Port = "53"

strRequest="www.gfi.com"

rawdata = Array(0,3,1,0,0,1,0,0,0,0,0,0,3, &H77, &H77, &H77, &H03, &H67, &H66, &H69, &H03, &H63, &H6F,&H6D, 0,0,1,0,1)

Set SocketObject = Socket.OpenUdp()

If Not SocketObject is Nothing Then

'check to see that the Object returned successfully

SocketObject.SendTo IP,port,rawdata

Response = SocketObject.Recv(1024)

For a = UBound(response)-3 To UBound(response)

echo(Response(a))

If a <> UBound(response) Then

echo(".")

End If

Next a

SocketObject.Close

End If

End Function