|
TriComm is a commercially avalable communications C++ library [ learn more about purchasing the source code ].
It allows to generically establish TCP/IP, RS-232 serial or Bluetooth
connections and operate them via the same API. Ideal for
transport-independent communications applications, such as terminals for
custom equipment.
TriComm is intended for companies and individuals involved into development of
software that works on Palm OS based platforms.
With the help of TriComm, developers of utilities, terminal software,
games and corporate systems for Palm PDAs would be able to make their
solutions wireless and completely transport-independent. With the use
of this library, development and opportunity costs are reduced by
eliminating the need to build separate Bluetooth, RS-232 serial and
TCP/IP APIs for each application.
In the following example, you can see how simple a client session can be
written with TriComm:
TriComm *comm = new TriBluetooth;
std::string buf;
try {
comm->Connect();
*comm << "Say something: ";
*comm >> buf;
*comm << "You have said: " << buf << "\r\n";
comm->Flush();
comm->Disconnect();
} catch(TriCommException &e) {
FrmCustomAlert(ExceptionAlert, e.getMessage().c_str(), 0, 0);
}
The library does everything for you. For Bluetooth, it locates the
device, opens a selection dialog, then establishes an L2CAP connection
and then RFCOMM/SPP socket to the remote device. You need only
concentrate on the logic. Use the device as a C++ stream, no matter if it's
a Bluetooth or TCP/IP connection, or even a serial cable!
However, some procotols require additional parameters before a connection can
be made. Let's suppose we have a TCP/IP port 80 on the www.bluetooth.com
located somewhere in the Internet. We also want to connect to it using an HTTP
proxy (method CONNECT, with password authentification). In this case, our code
will start with the following:
TriTCP *tcp = new TriTCP();
tcp->setProxy("http://user1:secret@proxy,mynet:3128/";
tcp->setHost("www.bluetooth.com");
tcp->setPort(80);
comm = tcp;
After setting the hostname and port number, go ahead with the SAME code
snippet as it was given above.
Now, to accept a Bluetooth connection, the following few lines of code
are required.
TriBluetooth *bt = new TriBluetooth();
bt->setName("my Palm device");
bt->Listen();
*bt << "kudos to the newly connected client!";
Finally, the best trick is:
TriComm *comm;
switch(transport) {
case tBluetooth:
comm = new TriBluetooth();
break;
case tTCP:
comm = new TriTCP();
comm->setHost("www.tridone.com");
comm->setPort(80);
break;
case tSerial:
comm = new TriSerial();
comm->setBaudRate(9600);
break;
}
comm->Connect();
*comm << "I really do not care which transport is used!\r\n";
*comm << "I simply send this text like it was a standard stream!\r\n";
As you can see, our library does all the dirty work related to handling
of communication-related parts of your application. So why re-invent the
wheel when simply using this product your work can be done much faster?
|