Click or drag to resize

CSocket.GetLineFrom Method

X#
Wait for connection and extract first line from incoming data.

Namespace:  VO
Assembly:  VOInternetClasses (in VOInternetClasses.dll) Version: 2.19
Syntax
 VIRTUAL METHOD GetLineFrom(
	cIP REF STRING,
	nRemPort REF DWORD
) AS STRING
Request Example View Source

Parameters

cIP
Type: String
Reference to a string to receive the client's IP address.
nRemPort
Type: DWord
Reference to a DWORD value to receive the client's port number.

Return Value

Type: String
String containing the received line, if successful; otherwise, NULL_STRING
Remarks
This method waits for data packages and extracts the first line from input data. Besides this, GetLineFrom() extracts the IP address and port number associated with the received Data. This method can be used by UDP sockets to retrieve datagram packages sent via the Internet.
Examples
The following example implements a simple socket server function listening for the first datagram package at port 7:
X#
 1FUNCTION ServerTest2()   AS VOID PASCAL
 2LOCAL oSocket   AS CSocket
 3LOCAL cData     AS STRING
 4LOCAL cFrom     AS STRING
 5LOCAL nPort     AS INT
 6oSocket  := CSocket{SOCK_DGRAM}
 7IF oSocket:bind(7, NULL_STRING, AF_INET)
 8oSocket:TimeOut := 10000
 9cData := oSocket:GetLineFrom(@cFrom, @nPort)
10IF cFrom == NULL_STRING
11? "Timeout expired, no data received :-("
12ELSE
13? "Data received from ", cFrom, ;
14, "Client port: ", NTrim(nPort)
15? "Received data:" , cData
16ENDIF
17ENDIF
18oSocket:Close()
19RETURN
See Also