breve Documentation: version 1.9 | ||
---|---|---|
<< previous | Chapter 10. Networking | next >> |
The NetworkServer object can accept connections from regular web-browsers. After the NetworkServer starts running, you can get the address that clients should connect to by using the method get-url. The URL will be the hostname (or IP address) of the server machine, followed by a ":portNumber".
When a web-client connects to the server, it may do one of two things: it may execute a command in the simulation's controller object, or it may request an HTML page.
To execute a method in the controller instance, simply append the method name to the end of the URL. If you wish to pass in either int or double arguments, they can be added afterwards, delimited by underscores. Other types may currently not be passed via the web interface. Here are some examples:
1 http://myserver:33333/turn-agent-blue 2 http://myserver:33333/set-agent-color_.2_.4_.6 |
The controller methods called may optionally return a string which will determine what information is sent back to the web-browser. If the string ends with ".html", breve will try to load data from an HTML on the local disk and send it back to the web-browser (sending HTML files is described in more detail in the next section). Otherwise, the string itself is returned to the web-broswer.
If an HTTP request to a breve network server ends with ".html", breve will try to provide the web-browser with an HTML file from the local disk. This feature is not typically used to serve informational web files as a normal web server might—instead, it should be used to serve files containing "links" that will execute controller commands in the simulation, as described above (Section 10.3.1).
Additionally, you can set an "index" page that will be served to the web-browser when they send a request to your server without an actual page or method request, for exampe, http://myserver:33333. This index page can be set using the method set-index-page.
<< previous | breve Documentation table of contents | next >> |
Sending and Receiving breve Objects | up | Plugins |