Previous | Up | Next |
This function creates a new http server on a specific port, and defines the callback function on requests : requests are firts bufferized on server side. When the whole request is received, the callback is evaluated with following arguments :Parameters
HTTPcon reference to the connection associated to the request u0 user parameter S request string
Then the callback should analyze this request (using 'strextr' for the header, and strfind to determine the beginning of post data). The callback must return a string :
- if the string is not nil, it is the response to the request. This is synchronous mode : the callback provides the full answer, and the connection will close automatically once it is transmitted.
- if the string is nil, this is the asynchronous mode. The connection is pending, and the server will user HTTPsend,HTTPsendFile,closeHTTPcon to send data and close connection.
Do not forget that the answer must start with a http header, such as :
HTTP/1.0 200 OK\13\10Server: SCOL HTTP server\13\10Content-Type: text/html\13\10\13\10
HTTPserver startHTTPserver ( Chn _channel_ I _port_ fun [HTTPcon u0 S] S _callback_ u0 _user_ )
Return value
_channel_ any channel _port_ Tcp-IP port number _callback_ callback fired when request is received. Can be nil. _user_ user parameter. Can be nil.
new http server
Error :