DTS Application Library
0.2.3
Application library containing referenced objects and interfaces to common libraries
|
Echo server using 1 server and 2 clients. More...
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <openssl/ssl.h>
#include <dtsapp.h>
Go to the source code of this file.
Functions | |
void | accept_func (struct fwsocket *sock, void *data) |
This function does nothing and is here for completeness. More... | |
void | server_func (struct fwsocket *sock, void *data) |
Server thread data is available. More... | |
void | client_func (struct fwsocket *sock, void *data) |
client thread data is available. More... | |
void | socktest (const char *ipaddr, int tcp, int ssl) |
Bassed on the options create server and clients. More... | |
void | unixsocktest (const char *socket, int protocol) |
Same test as for socktest() but for unix domain sockets. More... | |
FRAMEWORK_MAIN ("Socket Client/Server Echo (TCP/TLS/UDP/DTLS)","Gregory Hinton Nietsky","gregory@distrotech.co.za","http://www.distrotech.co.za", 2013,"/var/run/sockettest", FRAMEWORK_FLAG_DAEMONLOCK, NULL) | |
Initialise the application under the library replacing main() More... | |
Echo server using 1 server and 2 clients.
Simple implementation of a echo server shoeing the network socket interface it creates 1 server and 2 client threads the server echos back what is sent. the sockets support ipv4 and ipv6 and can be UDP or TCP with or without TLS/SSL support.
On application start using FRAMEWORK_MAIN a licence banner is displayed no flags are set as i wish to daemonize after checking the command line arguments.
There is a run/lock file created failure to lock this file prevents execution.
Once the sockets are created and threads started i sleep the main thread for 5 seconds before exiting the system will make sure all threads stop before leaving.
As you can see the progam initiliztion and flow has been greatly simplified by having these tasks managed.
Definition in file socket.c.
void accept_func | ( | struct fwsocket * | sock, |
void * | data | ||
) |
This function does nothing and is here for completeness.
When a new connection is recieved this function will be executed to allow processing of the connection.
sock | Reference to new socket |
data | Reference to data suppled on thread start |
Definition at line 36 of file socket.c.
Referenced by socktest().
void client_func | ( | struct fwsocket * | sock, |
void * | data | ||
) |
client thread data is available.
There is no need to worry about UDP support in client trhead callbacks and use of socketread / socketwrite is all that is required.
sock | Reference to socket data is available on. |
data | Reference to data held by thread. |
Definition at line 66 of file socket.c.
References fwsocket::sock, socketread(), and socketwrite().
Referenced by socktest(), and unixsocktest().
FRAMEWORK_MAIN | ( | "Socket Client/Server Echo (TCP/TLS/UDP/DTLS)" | , |
"Gregory Hinton Nietsky" | , | ||
"gregory@distrotech.co.za" | , | ||
"http://www.distrotech.co.za" | , | ||
2013 | , | ||
"/var/run/sockettest" | , | ||
FRAMEWORK_FLAG_DAEMONLOCK | , | ||
NULL | |||
) |
Initialise the application under the library replacing main()
[main]
[main]
Definition at line 167 of file socket.c.
References daemonize(), socktest(), and unixsocktest().
void server_func | ( | struct fwsocket * | sock, |
void * | data | ||
) |
Server thread data is available.
This function executes when the server socket has data to read the socket will need to be read from using socketread[_d] socketread_d is a wrapper arround recvfrom and socketwerite_d is a wrapper arround sendto this is important when dealing with un encrypted UDP sessions where the socket needs sendto addresss to send data too.
sock | Reference to socket data is available on. |
data | Reference to data held by thread. |
Definition at line 48 of file socket.c.
References fwsocket::sock, socketread_d(), and socketwrite_d().
Referenced by socktest(), and unixsocktest().
void socktest | ( | const char * | ipaddr, |
int | tcp, | ||
int | ssl | ||
) |
Bassed on the options create server and clients.
ipaddr | As supplied on the command line |
tcp | Set to non zero if using TCP. |
ssl | Set to non zero if TLS/SSL is required. |
Definition at line 86 of file socket.c.
References accept_func(), client_func(), close_socket(), dtlsv1_init(), server_func(), socketclient(), socketserver(), socketwrite(), sslv3_init(), tcpbind(), tcpconnect(), udpbind(), and udpconnect().
Referenced by FRAMEWORK_MAIN().
void unixsocktest | ( | const char * | socket, |
int | protocol | ||
) |
Same test as for socktest() but for unix domain sockets.
Unix domain sockets are "file" sockets and function in similar way to network sockets there scope is local to the machine so are often used for inter process control and networkless services. Instead of a IP address a file name is specified that is created by the server.
socket | File name to create server on and connect too. |
protocol | Theis is either SOCK_STREAM or SOCK_DGRAM and are similar to TCP/UDP respectivly. |
Definition at line 139 of file socket.c.
References client_func(), close_socket(), server_func(), socketwrite_d(), unixsocket_client(), and unixsocket_server().
Referenced by FRAMEWORK_MAIN().