Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- NetLib for Clipper, Version 6.0 - n_spxrecv( [ @<cbuffer> [, @<hnetaddress> ] ] ) http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
N_SPXRECV( [ @<cBuffer> [, @<hNetAddress> ] ] )


Parameters

<cBuffer>
Name of a memory variable to receive the message. It must be passed by 
reference (that is, prefixed with @). The maximum length of a single 
message is 512 bytes.

<hNetAddress>
Name of a memory variable to receive the sender's network address. It 
must be passed by reference (that is, prefixed with @).


Returns

Positive integer, the connection number, if an SPX message has been 
received. A connection must have been previously established with 
N_SPXLISTEN() or N_SPXCONNECT() for SPX messages to be received.

Zero if no message has been received.

Negative integer if a previously established connection has 
disconnected. In this case, the other station may have ended the 
application, logged out, or issued N_SPXDISCONNECT().


Description

Determines if an SPX message is waiting on the queue and, optionally, 
retrieves it.

If N_SPXRECV() is called with no arguments, the return value will 
indicate whether an SPX message is waiting in NetLib's internal receive 
queue. Although you can use this form to monitor message traffic, you 
should not delay too long before reading the message, since space in 
the queue is limited.

If a message is waiting on the queue and a reference to a memory 
variable is passed as the first or only argument, the message will be 
transferred from the queue to the variable.

If a reference to a memory variable is passed as a second argument, the 
sender's network address will be stored in the variable.

Messages are fetched from the queue in order of their arrival. It is 
not possible to retrieve messages from one open connection but not 
another. Thus if you are transferring a file in packets of 512 bytes, 
you must either check the connection number for each incoming packet 
returned by N_SPXRECV(), or make sure that the receiving station has 
only one open connection.


Examples

* Receive a message in listen mode
FUNCTION WaitSPX
   LOCAL cBuffer, nConnection
   nConnection = 0
   DO WHILE nConnection = 0      // Wait for a connection
      nConnection = N_SPXLISTEN()
   ENDDO
   ? 'CONNECT'                  // Connection made
   DO WHILE N_SPXRECV() != 0    // Wait for a message
   ENDDO
   ? 'Receiving a message...'
   ? 'Connection number: ', nConnection
   N_SPXRECV(@cBuffer)          // Collect it
   ? 'Bytes received: ', LEN(cBuffer)
RETURN cBuffer

* Same thing using an event trap
N_SPXLISTEN()                   // Listen mode
N_ONSPX('GetSPX')               // Set event trap
.
.
.
PROCEDURE GetSPX
   LOCAL cBuffer, nConnection
   IF N_SPXRECV() = 0           // Connection made
      ? 'CONNECT'
   ELSE                         // Message received
      ? 'Receiving a message...'
      nConnection = N_SPXRECV(@cBuffer)
      ? 'Connection number: ', nConnection
      ? 'Bytes received: ', LEN(cBuffer)
   ENDIF
   .
   .
   .
RETURN



See Also: N_ONSPX() N_SPXLISTEN()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson