c++ - Boost::ASIO cannot write back to client from server -


i have couple questions regarding boost asio.

i'm running problem clients can connect server, , asynchronously send data, cannot receive back. the async_write callback gets error: "the file handle supplied not valid". find strange couple reasons:

  1. when client connects initially, check socket.isopen() on server, , returns true.
  2. the fact client can still send data makes me think it's server side problem, or firewall problem (which find odd because server , client both on same computer (i'm using "localhost" connect now).

some more info...

tcp sockets.

i'm using boost , allegro side-by-side, , both boost , allegro threads being used. have io_service running in boost thread (server , client):

boost::asio::io_service::work work( io_service ); boost::thread io_thread( boost::bind( &boost::asio::io_service::run, &io_service ) ); 

and that's being called before create sockets.

the allegro threads hold allegro event loops, nothing special there.

i'd not have post source code, it's pretty large , complicated, , i'd rather not try , simplify basic case. can if it's necessary though.

my sockets wrapped class in shared pointer created , passed around rather than regular pointer (not sure if matters, i'm new boost).

thank can provide in determining why cannot write clients have connected to.

neil

edit: requested code segments:

async_read/write (server) , callback functions:

void serverconnection::async_read() {     if( this->m_socket.is_open() == false )     {         std::cerr << "socket closed... (read)\n";     }      boost::asio::async_read( this->m_socket,                              boost::asio::buffer( &m_input, sizeof( m_input ) ),                              boost::bind( &serverconnection::read_callback,                                           shared_from_this(),                                       boost::asio::placeholders::error,                                       boost::asio::placeholders::bytes_transferred ) ); }  void serverconnection::async_write(const packet_list &packet, packet_id id, uint8_t rr) {     this->m_output.data = packet;     this->m_output.head.opcode = id;     this->m_output.head.sender_id = 0;     this->m_output.head.response_required = rr;      if( this->m_socket.is_open() )     {         std::cerr << "socket closed... (write)\n";     }      boost::asio::async_write( this->m_socket,                               boost::asio::buffer( &m_output, sizeof( m_output ) ),                               boost::bind( &serverconnection::write_callback,                                            shared_from_this(),                                            boost::asio::placeholders::error,                                            boost::asio::placeholders::bytes_transferred ) ); }  void serverconnection::read_callback( const boost::system::error_code &error,                                   size_t /*read_count*/ ) {     if( error )     {         std::cerr << "error reading: " << error.message() << std::endl;         return;     }      std::cerr << "server reading data...\n";      if( this->m_event_dispatcher != nullptr )     {         allegro_event event;          if( m_input.head.opcode == c_accept )         {             event.type = 513;         }         else         {             event.type = 512;             event.user.data1 = (intptr_t)&m_input;         }          al_emit_user_event( this->m_event_dispatcher, &event, nullptr );     }     else     {         std::cerr << "why null....\n";     }      async_read(); }  void serverconnection::write_callback(const boost::system::error_code &error,                                   size_t /*write_count*/ ) {     // after write, don't need except error checking.     if( error.value() )     {         std::cerr << "error writing client. " << error.message() << std::endl;     } } 


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -