NETLink::Accept()

Description

Accept() is used to accept count items into the data array.

Call Signature

int Accept ( any ptr data [, int count] )

Return Value

int

1 is returned if successful, 0 if not.

Arguments

any ptr data:

Pointer to an array of type byte, char, int, float or double into which data should be accepted.

[ int count ]:

Number of items of the type of data to be accepted. If not specified the count is derived from the size of the data array.

Remarks

The data will not be manipulated in any way before being written into the data array. If data is not of one of the indicated types, an error will occur.

Example

In this example we want to read a variable number of (x,y) vertices into an array. First, we read the count. Next, we allocate just the right amount of buffer space and accept the points into it. In this second Accept() call we can depend on the Accept() call detecting the size of the array and so we don't have to pass the count in since pointer variables carry around the size of their array with them.


 local NETLink ptr poLink 
 local NetPort ptr poPort

 ! Established a port on the localhost
 poPort = NETPortCreate("PORT=1306")
 
 ! Display port id
 print poPort.PortId

 ! Loop and receive vector data being sent
 while(1=1)
	poLink = poPort.CheckMessage( 1.0 )
	if( poLink <> NULL )then
		call ReceiveVector(poLink)
	endif
 endwhile

 ! Destroy Port
 call poPort.Destroy

define function ReceiveVector(poLink)
 local int i
 local int j
 local double ptr xy_pts
 local int ptr cnt

 ! Allocate memory
 cnt=EAlloc(int,1)

 ! Get number of vertices in xy_pts vector
 if ( poLink.Accept(cnt) <> 0 ) then

	! Allocate memory - cnt * pairs of doubles
	xy_pts = EAlloc(double, cnt[1]*2)

	! Get vector data
	if ( poLink.Accept( xy_pts ) > 0 ) then

		! Display data received
		for  i=0 to cnt[1] - 1
			j=2*i
			print "(",xy_pts[1+j],",",xy_pts[2+j],")"
		endfor

		! Send acknowledgement - send size back
		if ( poLink.Send( cnt ) = 0 ) then
			print "Error: acknowledegment could not be sent"
		else
			print "Success receiving vector data at time = " + f$time 
		endif
    endif
	call EFree(xy_pts)
 endif
 call EFree(cnt)
enddefine

See also

NETLink class

Inter-process communication

© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.