<para>Apart from the native Tarantool client driver, you can always use a <emphasisrole="strong">Memcached</emphasis> driver of your choice, after enabling Memcached protocol in the configuration file.</para>
<sectionxml:id="connector-packet-example">
<title>Packet example</title>
<para>
The Tarantool API exists so that a client program can send a request packet
to the server, and receive a response. Here is an example of a what the client
would send for <command>INSERT INTO t0 VALUES ('A','BB')</command>. The BNF description of the components
is in file <linkxlink:href="https://github.com/tarantool/tarantool/blob/master/doc/box-protocol.txt"xlink:title="A complete BNF of Tarantool client/server protocol">doc/box-protocol.txt</link>.
</para>
<informaltableframe='topbot'>
<tgroupcols='5'align='left'colsep='1'rowsep='1'>
<colspeccolname='c1'/>
<colspeccolname='c2'/>
<colspeccolname='c3'/>
<colspeccolname='c4'/>
<colspeccolname='c5'/>
<thead>
<row>
<entry>Component</entry>
<entry>Byte#0</entry>
<entry>Byte#1</entry>
<entry>Byte#2</entry>
<entry>Byte#3</entry>
</row>
</thead>
<tbody>
<row>
<entry>type</entry>
<entry>13</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
</row>
<row>
<entry>body_length</entry>
<entry>17</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
</row>
<row>
<entry>request_id</entry>
<entry>1</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
</row>
<row>
<entry>space_no</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
</row>
<row>
<entry>flags</entry>
<entry>2</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
</row>
<row>
<entry>cardinality</entry>
<entry>2</entry>
<entry>0</entry>
<entry>0</entry>
<entry>0</entry>
</row>
<row>
<entry>field[0] size</entry>
<entry>1</entry>
<entrynamest="c1"nameend="c4"></entry>
</row>
<row>
<entry>field[0] data</entry>
<entry>65</entry>
<entrynamest="c2"nameend="c4"></entry>
</row>
<row>
<entry>field[1] size</entry>
<entry>2</entry>
<entrynamest="c2"nameend="c5"></entry>
</row>
<row>
<entry>field[1] data</entry>
<entry>66</entry>
<entry>66</entry>
<entrynamest="c3"nameend="c4"></entry>
</row>
</tbody>
</tgroup>
</informaltable>
<para>
Now, one could send that packet to the tarantool_box server,
and interpret the response (box-protocol.txt has a description
of the packet format for responses as well as requests).
But it would be easier, and less error-prone, if one could
invoke a routine that formats the packet according to typed
parameters. Something like <code>response=tarantool_routine("insert",0,"A","B");</code>.
And that is why APIs exist for drivers for C, Perl, Python, PHP, Ruby, and so on.
</para>
</section>
<sectionxml:id="connector-c">
<title>C</title>
<para>
Please see <link
Here is a complete C program that inserts ['A','BB'] into space[0] via the C API for the
binary protocol. To compile, paste the code into a file named example.c and say <code>
gcc -o example example.c -I/<replaceable>tarantool-directory</replaceable>/connector/c/include</code>
where tarantool-directory = the directory that contains
the necessary file <filename>tp.h</filename>, and the default library path contains
the directory where Tarantool library files were placed at installation time.
Before trying to run, check that the server
(tarantool_box) is running on localhost (127.0.0.1) and its primary port is the default (33013) and
space[0]'s primary key type is string (space[0].index[0].key_field[0].type = "STR" in configuration file).
To run, say <code>./example</code>.
The program will format a buffer for sending an INSERT request, then open a socket connection
with the tarantool_box server at localhost:33013, then send the request, then check if the
server returned an error, then — if all is well — print "Insert succeeded". If the
row already exists, the program will print <quote>Duplicate key exists in unique index 0</quote>.
</para>
<programlisting><code>
#include <arpa/inet.h>
#include <stdio.h>
#include <tp.h> /* the usual Tarantool include */
int main ()
{
struct tp request; /* area for sending to server */
struct tp reply; /* area for getting server reply */
int fd; /* file descriptor for socket */
struct sockaddr_in tt; /* the usual socket address info */