Example code to test the nettobac package in a client scenario. More...
Go to the source code of this file.
Functions | |
FUNCTION_AS_INTEGER | newConn (BYVAL_AS_nettobacServer_PTR Ser, BYVAL_AS_n2bConnection_PTR Con) |
Callback function to handle a new connection. More... | |
FUNCTION_AS_INTEGER | disConn (BYVAL_AS_nettobacServer_PTR Ser, BYVAL_AS_n2bConnection_PTR Con) |
Callback function to handle a disconnect. More... | |
FUNCTION_AS_INTEGER | newData (BYVAL_AS_n2bConnection_PTR Con, BYREF_AS_STRING Dat) |
Callback function to handle a client request. More... | |
FUNCTION_AS_INTEGER | doServer (BYVAL_AS_USHORT Port=3490) |
Operate as a server. More... | |
int | main () |
Variables | |
STRING | HTML1 |
The startpage, loaded from local data folder. More... | |
STRING | HTML2 |
The second page, loaded from local data folder. More... | |
STRING | ICON |
An icon, loded over web. More... | |
STRING | HTTP |
The HTTP header. More... | |
STRING | EMSG |
The HTTP error message. More... | |
Example code to test the nettobac package in a client scenario.
Copyright (C) GPLv3, see ReadMe.md for details.
Definition in file example_server.bas.
FUNCTION_AS_INTEGER newConn | ( | BYVAL_AS_nettobacServer_PTR | Ser, |
BYVAL_AS_n2bConnection_PTR | Con | ||
) |
Callback function to handle a new connection.
Ser | the calling server instance |
Con | the connection in use |
This is a callback function that gets called by function doServer() in case of a new client connection request. It just outputs a message at the console window.
Definition at line 31 of file example_server.bas.
FUNCTION_AS_INTEGER disConn | ( | BYVAL_AS_nettobacServer_PTR | Ser, |
BYVAL_AS_n2bConnection_PTR | Con | ||
) |
Callback function to handle a disconnect.
Ser | the calling server instance |
Con | the connection in use |
This is a callback function that gets called by function doServer() in case of a client peer closed the connection. It just outputs a message at the console window.
Definition at line 48 of file example_server.bas.
FUNCTION_AS_INTEGER newData | ( | BYVAL_AS_n2bConnection_PTR | Con, |
BYREF_AS_STRING | Dat | ||
) |
Callback function to handle a client request.
Con | the connection in use |
Dat | the message from the client |
This is a callback function that gets called by function doServer() in case of a data request from a connected client peer. It analyses the request (message in Dat
) and sends an appropriate response (via hppt protocol). Some responses are pre-defined (read from files), others get generated depending on the client message.
Definition at line 67 of file example_server.bas.
FUNCTION_AS_INTEGER doServer | ( | BYVAL_AS_USHORT | Port = 3490 | ) |
Operate as a server.
END
the programThis function creates a nettobacServer instance and check in a loop for new connection requests and for requests from already connected client peers. In case of events is call callback functions
"newConn"
: when a new client requests a connection"newData"
: when a connected client requests data"disConn"
: when a connection gets closedThe loop continues when the function returns 0 (zero). Ohterwise all connections get closed and the nettobacServer instance gets DELETE
d. Also any keystroke breaks the main loop.
Definition at line 146 of file example_server.bas.
int main | ( | ) |
Definition at line 183 of file example_server.bas.
STRING HTML1 |
The startpage, loaded from local data folder.
Definition at line 13 of file example_server.bas.
STRING HTML2 |
The second page, loaded from local data folder.
Definition at line 13 of file example_server.bas.
STRING ICON |
An icon, loded over web.
Definition at line 13 of file example_server.bas.
STRING HTTP |
The HTTP header.
Definition at line 13 of file example_server.bas.
STRING EMSG |
The HTTP error message.
Definition at line 13 of file example_server.bas.