Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: "Brian J. McCarthy" <mccarthy@hndymn.zko.dec.com>
To: "CSEE Transport HK Ltd. (3705)" <hk3705@csee-transport-hk.com.hk>
Subject: Re: socket-stream-C++
Date: 1999/03/18	[thread overview]
Message-ID: <36F0EA67.EBEF5E94@hndymn.zko.dec.com> (raw)
In-Reply-To: 7cngte$kuu$1@imsp009a.netvigator.com



"CSEE Transport HK Ltd. (3705)" wrote:
> 
> Hi,
> 
> I've got a question regarding the use of sockets with streams in C++ under
> Digital Unix 3.2c/g.
> 
> I've tried the following and it *seems* to work:
> 1. use socket() and connect() to get a file descriptor for an opened socket.
> (connected to an echo port on a remote machine)
> 2. created an instance of ifstream and ofstream with the fd.
> 3. sent something to ofstream and got something back from ifstream.
> 
> 4. tried with a single fstream(fd) instead of ifstream/ofstream.
> 5. sent something and got something back.
> 
> This, so far, has convinced me that I can use fstreams on sockets.  Now,
> what's the implication of using a socket this way?  I can fine-tune the
> socket with C calls, so it's not a problem.  What's the trade-off for
> applying a fstream on the socket?  Can I access binary data as well as ASCII
> data?
> 

> Has anyone tried this?  Can't say I'm a newbie, but this is definitely the
> first time I tried connecting a socket in C++...
> 

What you are trying (on a rather old version of the OS) is to make use of the 
C++ class library functions.  As you mention, you could do it directly
just coding in calls to the socket routines.

The C++ class library functions are layered on-top of the C runtime library so 
what you "get" by doing it this way is the features of the ifstream and
ofstream
classes - if you need them.

Binary data should not be an issue.

My general rule of thumb of for things like this is that do the functions I 
need to access (or that someone else might need to access) exist ?  In this
case
things like poling and selecting/waiting for input may not act as expected
which
means I may have to end up doing a read/write outside of the class calls to 
the sockets.  So, I'd stop right there and most likley invent my own class or
use straight socket calls.

So, ask yourself:  Does this provide all the functionality I need?

-- 
-----------------------------------------------------------------------
Brian J. McCarthy                  | mailto:Brian.J.McCarthy@compaq.com
Compaq Computer Corp. Nashua, NH   | Compaq C/C++ Runtime Libraries
-----------------------------------------------------------------------



           reply	other threads:[~1999-03-18  5:00 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <7cngte$kuu$1@imsp009a.netvigator.com>]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox