summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml2
-rw-r--r--README.md47
-rw-r--r--changelog10
-rw-r--r--configure.ac6
-rw-r--r--src/Makefile.am3
-rw-r--r--src/examples/Makefile.am5
-rw-r--r--src/examples/echo/Makefile.am17
-rw-r--r--src/examples/echo/client.cpp54
-rw-r--r--src/examples/echo/server.cpp78
9 files changed, 214 insertions, 8 deletions
diff --git a/.travis.yml b/.travis.yml
index 369fe61..bb930c7 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -24,7 +24,7 @@ before_script:
script:
- make
- - make check
+ - make distcheck
os:
- linux
diff --git a/README.md b/README.md
index 8da3338..70bfa04 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,14 @@
psocksxx
========
+[![GitHub release](https://img.shields.io/github/release/nukedzn/psocksxx.svg)](https://github.com/nukedzn/psocksxx/releases)
[![Build Status](https://travis-ci.org/nukedzn/psocksxx.svg)](https://travis-ci.org/nukedzn/psocksxx)
A C++ wrapper for POSIX sockets
## Copyright and License
-Copyright (C) 2015 Uditha Atukorala.
+Copyright (C) 2013-2015 Uditha Atukorala.
This software library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
@@ -49,7 +50,7 @@ You can download source distributions from https://github.com/nukedzn/psocksxx/r
### Debian/Ubuntu packages
-Please check availability for your distribution first ([Debian](https://packages.debian.org/search?searchon=names&keywords=psocksxx), [Ubuntu](http://packages.ubuntu.com/search?suite=wily&section=all&arch=any&keywords=psocksxx&searchon=names)).
+Please check availability for your distribution first ([Debian](https://packages.debian.org/psocksxx), [Ubuntu](http://packages.ubuntu.com/psocksxx)).
$ sudo aptitude update
$ sudo aptitude install libpsocksxx-dev
@@ -80,6 +81,48 @@ autotools.
After that you can use the usual `./configure && make`
+## Usage
+
+Please take a look at [examples](https://github.com/nukedzn/psocksxx/tree/master/src/examples)
+for more details.
+
+### Simple Server
+
+``` c++
+
+// tcp socket stream
+psocksxx::tcpnsockstream ss;
+
+// network address to bind to
+psocksxx::nsockaddr naddr( "localhost", "21555" );
+
+// bind and listen
+ss.bind( &naddr, true );
+ss.listen();
+
+// accept a connection
+psocksxx::nsockstream * css = ss.accept();
+
+```
+
+### Simple Client
+
+``` c++
+// tcp socket stream
+psocksxx::tcpnsockstream ss;
+
+// connect
+ss.connect( "localhost", 21555 );
+
+// send a message
+ss << "hello" << std::endl;
+
+// receive a message
+std::string msg;
+ss >> msg;
+```
+
+
## API Documentation
* [v1.0](https://nukedzn.github.io/psocksxx/docs/v1.0)
diff --git a/changelog b/changelog
index f0b834d..448bb56 100644
--- a/changelog
+++ b/changelog
@@ -1,11 +1,15 @@
+1.1.0 - 29th November 2015
+ * Add examples
+ * Enforce Automake version check in configure.ac
+
1.0.0 - 04th November 2015
- * First stable release (no code changes since v0.0.6)
+ * First stable release (no code changes since v0.0.6)
0.0.6 - 03rd October 2014
- * Removing obsolete doxygen tags (bug #37)
+ * Remove obsolete doxygen tags
0.0.5 - 29th June 2014
- * Fixing inconsistent timeout behaviour on different systems
+ * Fix inconsistent timeout behaviour on different systems
0.0.4 - 10th November 2013
* bug fix - member functions should not be throwing exceptions if the
diff --git a/configure.ac b/configure.ac
index addd5a0..1a27829 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ([2.68])
-AC_INIT([psocksxx], [1.0.0], [https://github.com/nukedzn/psocksxx/issues])
+AC_INIT([psocksxx], [1.1.0], [https://github.com/nukedzn/psocksxx/issues])
AC_CONFIG_AUX_DIR([aux-build])
AC_CONFIG_MACRO_DIR([aux-build/m4])
AC_CONFIG_HEADERS([include/config.h])
@@ -37,7 +37,7 @@ LIBPSOCKSXX_LT_VERSION=1:3:1
AC_SUBST(LIBPSOCKSXX_LT_VERSION)
# init
-AM_INIT_AUTOMAKE([foreign])
+AM_INIT_AUTOMAKE([1.13 foreign])
LT_INIT()
# check for programs
@@ -80,6 +80,8 @@ AC_CONFIG_FILES([ \
lib/Makefile \
lib/psocksxx/Makefile \
src/Makefile \
+ src/examples/Makefile \
+ src/examples/echo/Makefile \
test/Makefile \
])
diff --git a/src/Makefile.am b/src/Makefile.am
index 0deabb1..e0bfe6b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,2 +1,5 @@
## [psocksxx] src/
+SUBDIRS = \
+ examples
+
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
new file mode 100644
index 0000000..3155e25
--- /dev/null
+++ b/src/examples/Makefile.am
@@ -0,0 +1,5 @@
+## [psocksxx] src/examples/
+
+SUBDIRS = \
+ echo
+
diff --git a/src/examples/echo/Makefile.am b/src/examples/echo/Makefile.am
new file mode 100644
index 0000000..a1ada4b
--- /dev/null
+++ b/src/examples/echo/Makefile.am
@@ -0,0 +1,17 @@
+## [psocksxx] src/examples/echo/
+
+AM_CPPFLAGS = -I$(top_srcdir)/lib
+noinst_PROGRAMS = echo-server echo-client
+
+echo_server_LDADD = \
+ $(top_builddir)/lib/psocksxx/libpsocksxx.la
+
+echo_client_LDADD = \
+ $(top_builddir)/lib/psocksxx/libpsocksxx.la
+
+echo_server_SOURCES = \
+ server.cpp
+
+echo_client_SOURCES = \
+ client.cpp
+
diff --git a/src/examples/echo/client.cpp b/src/examples/echo/client.cpp
new file mode 100644
index 0000000..9039755
--- /dev/null
+++ b/src/examples/echo/client.cpp
@@ -0,0 +1,54 @@
+/*
+* psocksxx - A C++ wrapper for POSIX sockets
+* Copyright (C) 2013-2015 Uditha Atukorala
+*
+* This file is part of psocksxx software library.
+*
+* psocksxx software library is free software; you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation; either version 3 of the License, or
+* (at your option) any later version.
+*
+* This software library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this software library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+
+#include <iostream>
+#include <string>
+#include <psocksxx/tcpnsockstream.h>
+
+
+int main() {
+
+ // tcp socket stream
+ psocksxx::tcpnsockstream ss;
+
+ // connect
+ try {
+ ss.connect( "localhost", 21555 );
+ } catch ( psocksxx::sockexception &e ) {
+ std::cerr << "[client] failed to connect to socket, exception" << e.what() << std::endl;
+ return 1;
+ }
+
+ // send a message
+ ss << "hello" << std::endl;
+
+ // get the echo back from server
+ std::string msg;
+ ss >> msg;
+
+ // print message
+ std::cout << "[server] " << msg << std::endl;
+
+ return 0;
+
+}
+
diff --git a/src/examples/echo/server.cpp b/src/examples/echo/server.cpp
new file mode 100644
index 0000000..2257847
--- /dev/null
+++ b/src/examples/echo/server.cpp
@@ -0,0 +1,78 @@
+/*
+* psocksxx - A C++ wrapper for POSIX sockets
+* Copyright (C) 2013-2015 Uditha Atukorala
+*
+* This file is part of psocksxx software library.
+*
+* psocksxx software library is free software; you can redistribute it and/or modify
+* it under the terms of the GNU Lesser General Public License as published by
+* the Free Software Foundation; either version 3 of the License, or
+* (at your option) any later version.
+*
+* This software library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public License
+* along with this software library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+
+#include <iostream>
+#include <string>
+#include <psocksxx/tcpnsockstream.h>
+
+
+int main( int argc, char **argv ) {
+
+ // tcp socket stream
+ psocksxx::tcpnsockstream ss;
+
+ // network address to bind to
+ psocksxx::nsockaddr naddr( "localhost", "21555" );
+
+ // bind
+ try {
+ ss.bind( &naddr, true );
+ } catch( psocksxx::sockexception &e ) {
+ std::cerr << "[server] failed to bind to socket, exception: " << e.what() << std::endl;
+ return 1;
+ }
+
+ // listen
+ try {
+ ss.listen();
+ } catch( psocksxx::sockexception &e ) {
+ std::cerr << "[server] failed to listen on socket, exception: " << e.what() << std::endl;
+ return 1;
+ }
+
+
+ // client socket stream
+ psocksxx::nsockstream * css;
+
+ // message buffer
+ std::string msg;
+
+ for (;;) {
+
+ // accept a new client
+ css = ss.accept();
+
+ (* css) >> msg;
+ std::cout << "[client] " << msg << std::endl;
+
+ // echo back
+ (* css) << msg << std::endl;
+
+ // close/cleanup client
+ delete css;
+
+ }
+
+ return 0;
+
+}
+