CSocket.accept 方法 |
命名空间: VO
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 8 9oSocket := CSocket{SOCK_STREAM} 10 11IF oSocket:bind(7, NULL_STRING, AF_INET) 12 oSocket:listen(1) 13 lRet := .F. 14 oSockMsg := oSocket:accept() 15 16 IF oSockMsg != NULL_OBJECT 17 cData := oSockMsg:GetLine() 18 oSockMsg:getpeername(@cFrom, @nPort) 19 ? "Connection accepted from ", cFrom, , client port: , NTrim(nPort) 20 ? "Received data: ", cData 21 lRet := .T. 22 ENDIF 23 24 oSockMsg:Close() 25ENDIF 26 27oSocket:Close() 28 29RETURN lRet