nettobac  0.0.0
Network features for FreeBASIC code
example_server.bas File Reference

Example code to test the nettobac package in a client scenario. More...

Include dependency graph for example_server.bas:

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...
 

Detailed Description

Example code to test the nettobac package in a client scenario.

Copyright (C) GPLv3, see ReadMe.md for details.

Since
0.0.0

Definition in file example_server.bas.

Function Documentation

FUNCTION_AS_INTEGER newConn ( BYVAL_AS_nettobacServer_PTR  Ser,
BYVAL_AS_n2bConnection_PTR  Con 
)

Callback function to handle a new connection.

Parameters
Serthe calling server instance
Conthe connection in use
Returns
0 (zero) to continue the server main loop, any other value to exit

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.

Since
0.0.0

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.

Parameters
Serthe calling server instance
Conthe connection in use
Returns
0 (zero) to continue the server main loop, any other value to exit

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.

Since
0.0.0

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.

Parameters
Conthe connection in use
Datthe message from the client
Returns
0 (zero) to continue the server main loop, any other value to exit

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.

Since
0.0.0

Definition at line 67 of file example_server.bas.

Here is the call graph for this function:

FUNCTION_AS_INTEGER doServer ( BYVAL_AS_USHORT  Port = 3490)

Operate as a server.

Returns
the value to END the program

This 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 closed

The loop continues when the function returns 0 (zero). Ohterwise all connections get closed and the nettobacServer instance gets DELETEd. Also any keystroke breaks the main loop.

Since
0.0.0

Definition at line 146 of file example_server.bas.

int main ( )

Definition at line 183 of file example_server.bas.

Variable Documentation

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.