SOCKET SERVER()
Contents
Purpose
Function to create a socket server listening on a port
Syntax
SOCKET_SERVER(<expN>, <expC>)
See Also
ACLASS(), ADDPROPERTY(), AMEMBERS(), COMPOBJ(), CREATEOBJECT(), DEFINE CLASS, DISPLAY CLASSES, DODEFAULT(), FOREACH, JSON_DECODE_FILE(), JSON_ENCODE(), LIST CLASSES, LOADOBJECT(), NEWOBJECT(), OBJECT(), PRINT_JSON(), PRINT_HTML(), PRINT_R(), PRINT_XML(), REMOVEPROPERTY(), REQUIRE_ONCE(), SAVEOBJECT(), SELECT, SOCKET_CLOSE(), SOCKET_LASTERROR(), SOCKET_OPEN(), SOCKET_PEEK(), SOCKET_READ(), SOCKET_WRITE(), WITH, Working with Sockets and Web Services, XML_DECODE_FILE()
Description
The SOCKET_SERVER() function is used to create a socket server listening on a port. The <expN> is the TCPIP port number to listen on. The <expC> is the procedure to call to handle the connection. The socket number returned from SOCKET_SERVER() should be stored for use in the other socket functions.
Example
proc myhandler(skt as numeric) private m_running = .t. do while m_running if socket_peek(skt) <= 0 sleep 1 loop endif data = socket_read(skt) // do what you want to do with the data enddo endproc // create a server listening on port 9000 skt = socket_server(9000, "myhandler") if skt < 0 // error endif