1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter9.The COMSTACK Module</title><meta name="generator" content="DocBook XSL Stylesheets V1.76.1"><link rel="home" href="index.html" title="YAZ User's Guide and Reference"><link rel="up" href="index.html" title="YAZ User's Guide and Reference"><link rel="prev" href="odr.debugging.html" title="4.Debugging"><link rel="next" href="comstack.introduction.html" title="2.Introduction"></head><body><link rel="stylesheet" type="text/css" href="common/style1.css"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter9.The COMSTACK Module</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="odr.debugging.html">Prev</a></td><th width="60%" align="center"></th><td width="20%" align="right"><a accesskey="n" href="comstack.introduction.html">Next</a></td></tr></table><hr></div><div class="chapter" title="Chapter9.The COMSTACK Module"><div class="titlepage"><div><div><h2 class="title"><a name="comstack"></a>Chapter9.The COMSTACK Module</h2></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="sect1"><a href="comstack.html#comstack.synopsis">1. Synopsis (blocking mode)</a></span></dt><dt><span class="sect1"><a href="comstack.introduction.html">2. Introduction</a></span></dt><dt><span class="sect1"><a href="comstack.common.html">3. Common Functions</a></span></dt><dd><dl><dt><span class="sect2"><a href="comstack.common.html#comstack.managing.endpoints">3.1. Managing Endpoints</a></span></dt><dt><span class="sect2"><a href="comstack.common.html#comstack.data.exchange">3.2. Data Exchange</a></span></dt></dl></dd><dt><span class="sect1"><a href="comstack.client.html">4. Client Side</a></span></dt><dt><span class="sect1"><a href="comstack.server.html">5. Server Side</a></span></dt><dt><span class="sect1"><a href="comstack.addresses.html">6. Addresses</a></span></dt><dt><span class="sect1"><a href="comstack.ssl.html">7. SSL</a></span></dt><dt><span class="sect1"><a href="comstack.diagnostics.html">8. Diagnostics</a></span></dt><dt><span class="sect1"><a href="comstack.summary.html">9. Summary and Synopsis</a></span></dt></dl></div><div class="sect1" title="1.Synopsis (blocking mode)"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="comstack.synopsis"></a>1.Synopsis (blocking mode)</h2></div></div></div><pre class="programlisting">
COMSTACK stack;
char *buf = 0;
int size = 0, length_incoming;
char server_address_str[] = "localhost:9999";
void *server_address_ip;
int status;
char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
int protocol_package_length = strlen(protocol_package);
stack = cs_create(tcpip_type, 1, PROTO_HTTP);
if (!stack) {
perror("cs_create"); /* use perror() here since we have no stack yet */
return -1;
}
server_address_ip = cs_straddr(stack, server_address_str);
if (!server_address_ip)
{
fprintf(stderr, "cs_straddr: address could not be resolved\n");
return -1;
}
status = cs_connect(stack, server_address_ip);
if (status != 0) {
fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
return -1;
}
status = cs_put(stack, protocol_package, protocol_package_length);
if (status) {
fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
return -1;
}
/* Now get a response */
length_incoming = cs_get(stack, &buf, &size);
if (!length_incoming) {
fprintf(stderr, "Connection closed\n");
return -1;
} else if (length_incoming < 0) {
fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
return -1;
}
/* Print result */
fwrite(buf, length_incoming, 1, stdout);
/* clean up */
cs_close(stack);
if (buf)
free(buf);
return 0;
</pre></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="odr.debugging.html">Prev</a></td><td width="20%" align="center"></td><td width="40%" align="right"><a accesskey="n" href="comstack.introduction.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4.Debugging</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">2.Introduction</td></tr></table></div></body></html>
|