Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Re: socket-stream-C++
       [not found] <7cngte$kuu$1@imsp009a.netvigator.com>
@ 1999-03-18  5:00 ` Brian J. McCarthy
  0 siblings, 0 replies; only message in thread
From: Brian J. McCarthy @ 1999-03-18  5:00 UTC (permalink / raw)
  To: CSEE Transport HK Ltd. (3705)



"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
-----------------------------------------------------------------------



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-03-18  5:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <7cngte$kuu$1@imsp009a.netvigator.com>
1999-03-18  5:00 ` socket-stream-C++ Brian J. McCarthy

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