Click or drag to resize

CSocket.accept Method

X#
Accept a new connection on a socket.

Namespace:  VO
Assembly:  VOInternetClasses (in VOInternetClasses.dll) Version: 2.21
Syntax
 VIRTUAL METHOD accept() AS CSocket
Request Example View Source

Return Value

Type: CSocket
A new CSocket object instance, if successful; otherwise, NULL_OBJECT.
Remarks
This method can be used to make Internet server applications wait for a client's connection.
Examples
The following example implements a simple socket server function listening for first connections at port 7:
X#
 1FUNCTION ServerTest()
 2LOCAL oSocket   AS CSocket
 3LOCAL oSockMsg  AS CSocket
 4LOCAL cData     AS STRING
 5LOCAL cFrom     AS STRING
 6LOCAL nPort     AS INT
 7LOCAL lRet      AS LOGIC
 8oSocket  := CSocket{SOCK_STREAM}
 9IF oSocket:bind(7, NULL_STRING, AF_INET)
10oSocket:listen(1)
11lRet := .F.
12oSockMsg := oSocket:accept()
13IF oSockMsg != NULL_OBJECT
14cData := oSockMsg:GetLine()
15oSockMsg:getpeername(@cFrom, @nPort)
16? "Connection accepted from ", cFrom, ;
17, client port: , NTrim(nPort)
18? "Received data: ", cData
19lRet := .T.
20ENDIF
21oSockMsg:Close()
22ENDIF
23oSocket:Close()
24RETURN lRet
See Also