To understand what is happening wefirst have to understand how an HTTP Request is handled.
At first, the client is opening a connection to the server and sends a package of information. This is the request. The request contains information like the URI the part after the actualy URL), things about the client like address and browser.
This connection wil stay open until we send information in form of the response back. After we sent the response, the connection will close and the server can no longer talk to the client. It is a very onesided relationship.
The WebServerDAT takes care of that request and response in the callbacks.
To take a look at the callbacks of our webserver we can click the small arrow on the bottom right side.
The moment we sent a request to the server, by hitting enter or reload in our browser, a connection gets established and the onHTTPRequest method gets calles. The server passes three arguments.
webServerDAT: This is a refference to the WebServerDAT operator. For now, we can ignore this part.
request: The request is a dictionary containing all the information the client sent to us. We can acces them by using a string as a key like this:
debug( request["clientAddress"] )
To send back data to the browser we need to change what we write into the response dictionary. Right now we set three elements of our response.
The statusCode is telling the browser how the request went on the server side. 200 just means “Everything is ok and there were no problems”. Depending on what we set the code to, the browser might behave differrently. So lets keep it at 200.
The statusReason is not as important for the receiver, but might be interresting for the user sitting in front of it. In this case we just say “OK”, but we could also set it to “Alrighty!”.
data is what we are after. This is the actual information or content we send back to the browser. Lets change things up a little bit by replacing the current “TouchDesigner:” with something different. How about the current FPS?
First lets place a performCHOP, and then refference the current FPS in our responsedata.
response['data'] = '<b>Current FPS: </b>' + str( op('perform1')['fps'] )
When refreshing the browser we should see the following:
And like this we created a simple monitoring tool to check our current FPS.