what exactly does this library do?

closed account (Dy7SLyTq)
so im new to networking, and found this library online and it looks really cool http://www.keithschwarz.com/interesting/code/?dir=nstream and just had some questions about it. firstly, what is it reading/writing? lets say i connect to google.com, and start reading from it, what will i get? is it html/js/css source? secondly, how well will this work in a thread?
It looks like it's an iostream binding for TCP/IP (using sockets). You'll also need the matching streambuf.
lets say i connect to google.com, and start reading from it, what will i get?
If you just connect, you probably wont get anything. You need to send a request.
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
	nstream nstr;
	nstr.open("www.computerhope.com", 80);

	nstr << "GET " << "/jargon/a/kirk.txt" << " HTTP / 1.0\r\n";
	nstr << "Host: " << "www.computerhope.com" << "\r\n";
	nstr << "Accept: */*\r\n";
	nstr << "Connection: close\r\n\r\n";
	nstr.flush();
	std::cout << nstr.rdbuf();
}



Edit: If you're looking to get into network programming I would recommend boost::asio it is far more feature full.
Last edited on
Topic archived. No new replies allowed.