https://github.com/jas-bar/tram
https://github.com/jas-bar/tram
c-plus-plus cmake cpp network raii socket
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/jas-bar/tram
- Owner: jas-bar
- License: mit
- Created: 2017-02-12T14:51:09.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-21T17:39:07.000Z (over 9 years ago)
- Last Synced: 2025-01-24T15:35:11.181Z (over 1 year ago)
- Topics: c-plus-plus, cmake, cpp, network, raii, socket
- Language: C++
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
tram
---------------

tram is a C++ networking & sockets library.
It is developed and tested on Linux.
tram's goal is to stay minimal in terms of dependencies, so it should be easy to port it to other platforms.
# Features & Concepts
- simple stream-like interface, but for sockets
- RAII sockets management: creating socket = connecting, destroying socket = disconnecting
## Getting Started
tram uses familiar stream-like interface for sockets.
## Connecting to server
```cpp
{
tram::Client client("127.0.0.1", "12334");
std::string res;
client >> res;
std::cout << res << std::endl;
// client socket is closed if no other client objects are using it
}
```
## Setting up server
```cpp
{
tram::Server server("12334");
tram::Client conn = server.acc();
conn << "H" << "A" << "H" << "a";
// conn is closed
// server is closed
}
```
# Using tram in your projects
Tram can install to `/usr/include` and `/usr/lib` directories. It also installs a `.pc` file to be usable with [pkgconfig](https://people.freedesktop.org/~dbn/pkg-config-guide.html#using) tool. It is, however, **not** required to use pkgconfig to link against tram.
```
$ git clone https://github.com/jas-bar/tram
$ cd tram
$ cmake .
$ make
$ sudo make install
```
Tram should now be available to you via pkgconfig.
If you are using CMake to build your project, you add this snippet to your `CMakeLists.txt`:
```
include(FindPkgConfig)
pkg_search_module(TRAM REQUIRED tram)
```
After this, `${TRAM_LIBRARIES}` and `${TRAM_INCLUDE_DIRS}` variables are defined, which can be utilized with `target_link_libraries` and `include_directories` respectively.
If everything is setup right, use `#include ` in your sources and you're ready to start coding.
For more information about this process, see pull request #12.
# Licensing
tram is under MIT license. See LICENSE for more information