0

Is it possible for C++' input stream to read from a chatroom like msn , yahoo and things like that and return some sort of message? just wondering as i search the net and most of it require client and server.

I am new to this

3 Answers 3

3

No; the two concepts have only a passing resemblance.

  1. C++ iostreams are a very low-level construct for reading bytes to and from operating system devices such as file systems, fifos, sockets, etc.
  2. Chat services are implemented over high-level protocols such as XMPP, which operate over TCP via socket APIs provided by the OS.

In short, they are chalk and cheese.

There have been nominal efforts to provide access to sockets via the iostream facility, which was designed to be extended in such ways. However, these libraries have never acquired significant traction in mainstream C++ programming. Even if they had, they would still be a long way off implementing a protocol as complex as XMPP.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes, if you can find (or write) a library to implement that abstraction.

As Marcelo says, chat services etc operate using complex protocols. But something similar can be said about stdio and file streams - there's a fair amount of complexity to writing to a file, or to a text-mode display (and that's not even mentioning a console window in a GUI). Most of that complexity is already abstracted away by the operating system and standard library.

A library can still be written to abstract away most of that complexity. That library can then provide objects that act as input and/or output streams, following the same conventions as the standard streams, and inheriting from the same bases.

This is probably a good approach, but AFAIK it's rare. Maybe I'm wrong about that - I never really program for this kind of thing. But if I'm right, a probable reason is that libraries are often written to be compatible with both C and C++.

Also, even among C++ programmers, stream abstractions aren't always considered a good feature. A lot of people would like to see them restricted to stdio and file I/O, and don't really recognise streams as a more general abstraction.

BTW - this isn't really a contradiction of Marcelos answer. That "if you can find (or write) a library" is a big if.

Comments

0

You can create some class, for example MY_CLIENT. In this class you need to implement functions

std::streamsize write( const char *s, std::streamsize n );
std::streamsize read( char* s, std::streamsize n );

In that functions you need to implement protocol of chat room logic, how send data to, and read.

After this look to boost::iostreams library. With it you can write smth like:

boost::iostreams::stream< MY_CLIEN> my_chat_stream;

And my_chat_stream you can use as std::istream, std::ostream for your program, with all c++ streams opportunites

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.