------------------------------------------ Sprech 0.1.9 API ------------------------------------------ Sprech has two different structs: * sprechServerC and * sprechClientC The functions you'll be using are as follows: * Setup / Cleanup * char sprechInit(void) * initializes sprech. call this before any other sprech functions. * returns 0 upon success, nonzero otherwise. * void sprechFini(void) * cleanup. call this at program termination. * Client Functions * sprechClientC *sprechClientOpen( char *hostname, unsigned short port ) * attempts to connect to port [port] on [hostname] * void sprechClientClose( sprechClientC * connection ) * closes a connection established by sprechClientOpen * Server Functions * sprechServerC *sprechServerOpen( unsigned short port ) * Opens up a server on port [port] of localhost * int sprechServerAccept ( sprechServerC * server ) * Accepts a connection from an opened server. returns 1 if no pending connections, 0 upon success. * In windows, it seems there is no non-blocking mode, so this will always wait for a connection. * int sprechServerAcceptWait ( sprechServerC * server ) * Accepts a connection. does not return until a connection happens. * void sprechServerCloseC( sprechServerC * server ) * Closes a server connection established by sprechServerOpen * void sprechServerClose( sprechServerC * server ) * Closes a server socket down completely * void sprechServerFree( sprechServerC * server ) * Frees memory used by a server structure. Unix allows multiple connections; windows only allows one for the time being. In unix, you fork for each connection. It is good to have the fork parent immediately close the newly established connection (server->slave). In the child fork, you immediately close the server->serverport. This keeps things from trampling on each other. See demo/server.c for an example of this. This will probably be handled internally in future verions. * Getting/Sending data * int sprechSend( sprechServerC *server, char *buffer, int len ) * sends len bytes of buffer thru server * int sprechSend(sprechClientC *client, char *buffer, int len ) * sends len bytes of buffer thru client * int sprechRecv( sprechServerC *server, char *buffer, int len ) * reads up to len bytes from server into buffer * int sprechRecv( sprechClientC *client, char *buffer, int len ) * reads up to len bytes from client into buffer These functions all return the number of bytes actually sent/received. Send/Recv block under windows, and do not block under unix. The desired behaviour is to never block, but windows makes non-blocking a bit more difficult, and I haven't figured out how to get it working just right yet. Further questions can be directed to sprech@softpixel.com.