KwikNet Overview
K
DAK
33
The client then uses procedure kn_select() to wait until some data from the server is
available for reading. The sample illustrates the proper use of the macros FD_ZERO,
FD_SET and FD_ISSET for manipulating socket sets. The client then uses procedure
kn_recv() to receive a 4 byte message, a long value from the server and confirms that
the received value is 10, the value sent incremented by 2.
Once the echoed value has been received from the server, the client uses
kn_shutdown()
to terminate all send and receive operations on its socket. The socket is then closed using
kn_close().
Logging
The KwikNet TCP/IP Sample Program includes a simple recorder for logging text
messages. The recorder saves the recorded text strings in a 30,000 byte memory buffer
until either 500 strings have been recorded or the memory buffer capacity is reached.
The application can generate messages by calling the
KwikNet log procedure
kn_dprintf(). This procedure operates similarly to the C printf() function except
that an extra integer parameter of value 0 must precede the format string. The sample
program uses this feature to record startup and shutdown messages. The client and server
record progress messages and log errors as they are detected.
KwikNet formats the message into a log buffer and passes the buffer to an application log
function for printing. Log function sam_record() in the KwikNet Application OS
Interface serves this purpose.
In a multitasking system the log buffer is delivered as part of an RTOS dependent
message to a print task. The print task calls kn_logmsg() in the KwikNet message
recording module to record the message and release the log buffer.
In a single threaded system, the log function sam_record() can usually call
kn_logmsg() to record the message and release the log buffer. However, if the message
is being generated while executing in the interrupt domain, the log buffer must be passed
to the KwikNet Task to be logged. The sample programs provided with the KwikNet
Porting Kit illustrate this process.
Shutdown
Once the client and server have completed their second scenario, the client calls
KwikNet
procedure kn_netstats() to record all network statistics gathered by KwikNet during the
session.
The client then calls procedure
kn_exit() to stop operation of the KwikNet TCP/IP Stack.
A final completion message is then logged. Note that the
KwikNet data logging services
continue to be used by the application even though the stack itself has ceased operation.
Finally, the client requests the operating system to shut down and return to the
main()
function.
Comments to this Manuals