GithubHelp home page GithubHelp logo

isabella232 / cpp-smpp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from onlinecity/cpp-smpp

0.0 0.0 0.0 1.17 MB

Small SMPP client implemented in C++

Home Page: onlinecity.dk

Shell 1.09% C++ 94.45% C 4.46%

cpp-smpp's Introduction

SMPP client implemented in C++

This is a simplified SMPP client lib for sending and receiving smses through the SMPP V3.4 protocol. It only implements a handful of the SMPP features.

Dependencies

To build this library you need and a c++11 compatible compiler:

We have built this library against boost 1.46, but it's known to work with boost 1.47 as well.

The following ubuntu packages should suffice for the dependices: libboost1.46-all-dev and libcppunit-dev.

If you dont wan't all the boost libs, try:

Installation

git clone [email protected]:onlinecity/cpp-smpp.git
cd cpp-smpp
cmake .
make
su
make install

There is both an offline unit test (./test/unittest) and an online unit test (./test/livetest). If you run make test you'll run them both via CTest. They can be run individually, which also allows you to view the results from CppUnit. The connection settings for the online test is found in test/connectionsetting.h.

Sending a SMS:

/*
 * transmit.cpp
 * Compile with (on Ubuntu):
 * g++ transmit.cpp -I/usr/local/include -lsmpp -lboost_system -lboost_regex -lboost_date_time
 */

#include <smpp/smppclient.h>
#include <smpp/gsmencoding.h>
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

using namespace boost;
using namespace boost::asio;
using namespace boost::asio::ip;
using namespace smpp;
using namespace oc::tools;
using namespace std;

int main(int argc, char** argv)
{
	boost::asio::io_service io_service;
	tcp::endpoint endpoint(ip::address_v4::from_string("127.0.0.1"), 2775);
	shared_ptr<tcp::socket> socket(new tcp::socket(io_service));
	socket->connect(endpoint);

	SmppClient client(socket);
	client.setVerbose(true);
	client.bindTransmitter("username", "password");

	SmppAddress from("CPPSMPP", smpp::TON_ALPHANUMERIC, smpp::NPI_UNKNOWN);
	SmppAddress to("4513371337", smpp::TON_INTERNATIONAL, smpp::NPI_E164);
	string message = "message to send";
	string smscId = client.sendSms(from, to, GsmEncoder::getGsm0338(message));

	cout << smscId << endl;
	client.unbind();

	return 0;
}

Receiving a SMS:

/*
 * receive.cpp
 * Compile with (on ubuntu):
 * g++ receive.cpp -I/usr/local/include -lsmpp -lboost_system -lboost_regex -lboost_date_time
 */

#include <smpp/smppclient.h>
#include <smpp/sms.h>
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>

using namespace boost;
using namespace boost::asio;
using namespace boost::asio::ip;
using namespace smpp;
using namespace std;

int main(int argc, char** argv)
{
	boost::asio::io_service io_service;
	tcp::endpoint endpoint(ip::address_v4::from_string("127.0.0.1"), 2775);
	shared_ptr<tcp::socket> socket(new tcp::socket(io_service));
	socket->connect(endpoint);

	SmppClient client(socket);
	client.setVerbose(true);
	client.bindReceiver("username", "password");

	SMS sms = client.readSms();
	cout << "source addr: " << sms.source_addr << endl;
	cout << "dest addr: " << sms.dest_addr << endl;
	cout << "SM: " << sms.short_message << endl;

	if ((sms.esm_class & smpp::ESM_DELIVER_SMSC_RECEIPT) != 0) {
		DeliveryReport dlr(sms);
		cout << "id: " << dlr.id << endl;
		cout << "err: " << dlr.err << endl;
		cout << "stat: " << dlr.stat << endl;
		cout << "done date: " << dlr.doneDate << endl;
		cout << "submit date: " << dlr.submitDate << endl;
	}

	client.unbind();

	return 0;
}

F.A.Q.

How do I enable delivery reports? You must set the registered delivery flag: client.setRegisteredDelivery(smpp::REG_DELIVERY_SMSC_BOTH);

Why do I get 'Failed to read reply to command: 0x4', 'Message Length is invalid' or 'Error in optional part' errors? Most likely your SMPP provider doesn't support NULL-terminating the message field. The specs aren't clear on this issue, so there is a toggle. Set client.setNullTerminateOctetStrings(false); and try again.

Can I test the client library without a SMPP server? Many service providers can give you a demo account, but you can also use the logica opensmpp simulator (java) or smsforum client test tool (linux binary). In addition to a number of real-life SMPP servers this library is tested against these simulators.

How do I set socket timeouts? You cannot modify the connect timeout since it uses the default boost::asio::ip::tcp socket. You can set the socket read/write timeouts by calling client.setSocketWriteTimeout(1000) and client.setSocketReadTimeout(1000). All timeouts are in milliseconds.

cpp-smpp's People

Contributors

cypres avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.