Skip to main content
GameDev.net gamedev.net
🔒 Locked

Std streams and sockets

Started by LizardCPP Apr 10, 2005 at 3:21 PM 3 replies 750+ views
Original Post
LizardCPP
LizardCPP
Can one connect std input/output streams to a socket (using WinSock 2.2)? Lizard
Fruny
Fruny
Not with the standard stream classes, no. You'll have to write your own or find one online.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
LizardCPP
LizardCPP
Ok there is no way one can extend the std classes to incorperate this kind of behaviour?

Lizard
Fruny
Fruny
Quote:
Original post by LizardCPP
Ok there is no way one can extend the std classes to incorperate this kind of behaviour?


Yes, there is. You need to create a stream buffer class derived from std::basic_streambuf (IIRC) that will do its read/writes through a socket (start by overloading the overflow and underflow member functions, then check out the rest of the virtual functions to see if changing them would be useful). You will then have to derive a stream class from std::iostream to encapsulate the stream buffer (namely to create the appropriate stream buffer instance and to provide open/close functions - the base std::iostream will provide the normal stream operations).

If you get involved in that kind of code a lot, consider buying "Standard C++ IOStreams and Locales" by Langer & Kreft.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.