1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 Index Data
3 * See the file LICENSE for details.
10 #include <yaz/comstack.h>
11 #include <yaz/tcpip.h>
13 static int comstack_example(const char *server_address_str)
17 int size = 0, length_incoming;
18 void *server_address_ip;
21 char *protocol_package = "GET / HTTP/1.0\r\n\r\n";
22 int protocol_package_length = strlen(protocol_package);
24 stack = cs_create(tcpip_type, 1, PROTO_HTTP);
26 perror("cs_create"); /* use perror() here since we have no stack yet */
30 server_address_ip = cs_straddr(stack, server_address_str);
31 if (!server_address_ip)
33 fprintf(stderr, "cs_straddr: address could not be resolved\n");
37 status = cs_connect(stack, server_address_ip);
39 fprintf(stderr, "cs_connect: %s\n", cs_strerror(stack));
43 status = cs_put(stack, protocol_package, protocol_package_length);
45 fprintf(stderr, "cs_put: %s\n", cs_strerror(stack));
49 /* Now get a response */
51 length_incoming = cs_get(stack, &buf, &size);
52 if (!length_incoming) {
53 fprintf(stderr, "Connection closed\n");
55 } else if (length_incoming < 0) {
56 fprintf(stderr, "cs_get: %s\n", cs_strerror(stack));
61 fwrite(buf, length_incoming, 1, stdout);
71 int main(int argc, char **argv)
73 YAZ_CHECK_INIT(argc, argv);
75 comstack_example(argv[1]);
82 * c-file-style: "Stroustrup"
83 * indent-tabs-mode: nil
85 * vim: shiftwidth=4 tabstop=8 expandtab