On most platforms, creating a simple Open Server application program involves these steps:
Step |
Function |
Routines |
---|---|---|
1 |
Set up the Open Server operating environment by allocating structures and setting global attributes, known as properties. |
cs_ctx_alloc srv_version srv_props |
2 |
Define error handling. Applications may install an error handling routine, which Open Server calls when it detects an error. Applications may also call the srv_sendinfo routine on an ad hoc basis to send error messages to the client, or srv_log to write to the log file. See “Errors” for details. |
srv_props(SRV_S_ERRHANDLE) |
3 |
Initialize the server. |
srv_init |
4 |
Install event-handling routines, which Open Server calls when client commands trigger Open Server events. An Open Server application does most of its work inside its event-handling routines. Refer to “Open Server events” for more information. |
srv_handle |
5 |
Start the server running. In this state, the server simply listens for client requests. |
srv_run |
6 |
Clean up and exit. |
cs_ctx_drop |
The example program in the following section demonstrates all but step 4; it does not install user-defined event handlers. Therefore, the default handlers will execute instead.