Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

11.4 Reading From a Portal

The first example program wrote to a portal, but didn't read any input. The next example expands on the first example by printing the first packet of output returned by the socket.

The only new lines of code are lines //1 and //2.

//1We obtain the next packet of information that arrives at the socket. There is no way to tell in advance how much data will be returned in the string.
//2Print whatever data arrived.

A problem with this new program is that it does not always handle all of the data sent by the server. More data could arrive after the first packet was printed, and we would never know it. To fix this, replace line //1 with this loop:

The revised version continues to receive data on the portal until the recv() function returns the null string, which happens when the server terminates the connection.

The wwwget example program uses code similar to this example to fetch a page of the World Wide Web using the HTTP protocol. Check it out for a real-life example of how to use the RWSocketPortal class.


Previous fileTop of DocumentContentsIndexNext file

©Copyright 2000, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.