#include <Poco/Net/StreamSocket.h>
#include <Poco/Net/SocketStream.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/StreamCopier.h>
#include <Poco/Thread.h>
#include <string>
constchar * host = "127.0.0.1";
int main()
{
std::string outstring;
Poco::Net::StreamSocket socket(Poco::Net::SocketAddress(host, "5221") );
Poco::Net::SocketStream ss(socket);
ss<<"This will get sent to the server!"<<std::endl;
ss.shutdownsend();
while (true)
{
if (socket.poll(100, SELECT_READ) == true)
{
if (Poco::copyToString(ss, outstring) > 0)
{
std::cout<<"Received "<<outstring<<" from sever"<<std::endl;
break;
}
}
Poco::Thread::sleep(100);
}
return 0;
}
Note: I didn't compile this. So some tweaking may be necessary. Could even remap std::cout to receive the string stream. I created a simple cout forwarder of TCP/IP using this method. It would buffer up then transmit then rebuffer. Worked pretty well. I remapped the cout to the socketstream