- Code: Select all
void FileServer::run()
{
_ready.set();
Poco::Timespan span(250000);
while (!_stop)
{
if (_socket.poll(span, Socket::SELECT_READ))
{
StreamSocket ss = _socket.acceptConnection();
std::string path;
try
{
for (int i = 0; i < 3; i++)
{
SocketStream str(ss);
BinaryReader r(str);
r >> path;
std::cout << i << " path is: " << path << std::endl;
}
}
catch (Poco::Exception& exc)
{
std::cerr << "FileServer: " << exc.displayText() << std::endl;
}
}
}
}
Client is:
- Code: Select all
StreamSocket ss;
unsigned short port = 1970;
std::string path;
ss.connect(SocketAddress("localhost", port));
for (int i = 0; i < 3; i++)
{
SocketStream str(ss);
BinaryWriter w(str);
w << "AAAA";
w.flush();
//Thread::sleep(1); // if no this code, only send one time,
//then server will hang up on second "r >> path;", why?
}





