My program uses 2 ports simultaneously in separate threads but when the second thread writes on its own connection with its own port it seems to complete successfully but does not send anything, I verified this using process monitor.
I have tried a single boost::asio::io_service for both threads and one for either thread, I tried calling run() on 1 or both threads or not at all and none of that makes a difference.
Here are the relevant methods:
const int conport=48625;
const int vidport=48624;
boost::asio::io_service iosvc;
boost::asio::ip::tcp::socket consock(iosvc);
void ControlThread::operator()(NameEdit* nameptr){
try{
boost::asio::ip::tcp::endpoint endp(boost::asio::ip::tcp::v6(), conport);
boost::asio::ip::tcp::acceptor acc(iosvc, endp);
iosvc.run();
boost::system::error_code ec;
acc: acc.accept(consock, ec);
boost::asio::streambuf buf;
auto n=boost::asio::read(consock, buf, boost::asio::transfer_exactly(1), ec);
buf.commit(n);
if(BufCast(buf)[0]!=2){
consock.close();
goto acc;
}
boost::asio::write(consock, boost::asio::buffer((char*)2, 1), boost::asio::transfer_exactly(1), ec);
ConMain(nameptr);
}catch(std::exception& ex){
MessageBoxExA(NULL, (LPCSTR)ex.what(), "Error", MB_ICONEXCLAMATION, 0);
}
}
boost::asio::ip::tcp::socket vidsock(iosvc);
void VideoThread::operator()(){
try{
boost::asio::ip::tcp::endpoint endp(boost::asio::ip::tcp::v6(), vidport);
boost::asio::ip::tcp::acceptor acc(iosvc, endp);
iosvc.run();
boost::system::error_code ec;
acc: acc.accept(vidsock, ec);
boost::asio::streambuf buf;
auto n=boost::asio::read(vidsock, buf, boost::asio::transfer_exactly(1), ec);
buf.commit(n);
if(BufCast(buf)[0]!=2){
vidsock.close();
goto acc;
}
boost::asio::write(vidsock, boost::asio::buffer((char*)2, 1), boost::asio::transfer_exactly(1), ec); // THIS write does not send
VideoThread::VidMain();
}catch(std::exception& ex){
MessageBoxExA(NULL, (LPCSTR)ex.what(), "Error", MB_ICONEXCLAMATION, 0);
}
}
I'm using boost 1.54 and Intel compiler v14 the visual studio 2012 project is an MFC executable.