From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,e9b3f2144aecebc6,start X-Google-Attributes: gidfee84,public From: "Brian J. McCarthy" Subject: Re: socket-stream-C++ Date: 1999/03/18 Message-ID: <36F0EA67.EBEF5E94@hndymn.zko.dec.com>#1/1 X-Deja-AN: 456102748 Content-Transfer-Encoding: 7bit References: <7cngte$kuu$1@imsp009a.netvigator.com> To: "CSEE Transport HK Ltd. (3705)" X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Compaq Computer Corporation Mime-Version: 1.0 Newsgroups: comp.unix.osf.osf1 "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 -----------------------------------------------------------------------