*BSD News Article 43802


Return to BSD News archive

Xref: sserve comp.infosystems.www.browsers.misc:140 comp.unix.questions:64164 comp.unix.bsd.freebsd.misc:1024 comp.unix.bsd:16576 comp.lang.c:100065
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!news.kei.com!news.mathworks.com!gatech!howland.reston.ans.net!nctuccca.edu.tw!news.cc.nctu.edu.tw!news.sinica!taob
From: taob@gate.sinica.edu.tw (Brian Tao)
Newsgroups: comp.infosystems.www.browsers.misc,comp.unix.questions,comp.unix.bsd.freebsd.misc,comp.unix.bsd,comp.lang.c
Subject: Simple socket/telnet library?
Date: 11 May 1995 10:54:56 GMT
Organization: Institute of Biomedical Sciences, Academia Sinica
Lines: 41
Message-ID: <3osqe0$5ei@gate.sinica.edu.tw>
NNTP-Posting-Host: @140.109.40.248

    I would like to write an extremely simple and brain-dead Web
browser for as part of an HTTP server benchmark.  Is there a library
of C routines someone has already put together that allows one to open
a connection to a host at a specific port and then send/receive text?
My knowledge of UNIX socket and TCP/IP programming is exactly zero.  :(
For example:

char *gethtml(char *hostname, int port, char *request, int bytes)
{
    int *open_socket;
    char *html;

    html = (char *)(malloc(bytes));

    if(!(open_socket=tcpopen(hostname, port)))
    {
        fprintf(stderr, "Could not connect to host!\n");
        exit(1);
    }

    tcpwrite(open_socket, request);
    tcpread(open_socket, html, bytes);
    tcpclose(open_socket);
    return(html);
}

    Right now I'm forking off a "lynx -source -dump" process for each
request, which gets expensive when you have ten or more of these
things going on one machine.  If there is a ready-made library with
functions akin to tcpopen(), tcpwrite(), tcpread() and tcpclose() that
works with a 4.4BSD system (FreeBSD 2.0, in my case), that would be
fantastic.  Source code fragments, tutorial files, primers, etc. also
gratefully accepted.  Thanks.

    BTW, is it possible to create a special file that is connected to
a host at a particular port, and be able to do something like "echo
'expn somealias' > special-file" and then "cat special-file" to read
from the socket?
-- 
Brian ("Though this be madness, yet there is method in't") Tao
taob@gate.sinica.edu.tw <-- work ........ play --> taob@io.org