voidgetthread(){boost::asio::io_serviceio_service;charline[chat_message::max_body_length+1];chat_roomroom_;chat_session_ptrnew_session(newchat_session(io_service,room_));while(std::cin.getline(line,chat_message::max_body_length+1)){usingnamespacestd;// For strlen and memcpy.chat_messagemsg;msg.body_length(strlen(line));memcpy(msg.body(),line,msg.body_length());msg.encode_header();new_session->deliver(msg);}}intmain(intargc,char*argv[]){try{if(argc<2){std::cerr<<"Usage: chat_server <port> [<port> ...]\n";return1;}boost::asio::io_serviceio_service;boost::threadt(boost::bind(getthread));chat_server_listservers;for(inti=1;i<argc;++i){usingnamespacestd;// For atoi.tcp::endpointendpoint(tcp::v4(),atoi(argv[i]));chat_server_ptrserver(newchat_server(io_service,endpoint));servers.push_back(server);}io_service.run();t.join();}catch(std::exception&e){std::cerr<<"Exception: "<<e.what()<<"\n";}return0;}
this is modified code of chat in Boost sample. I need to display from client in the server and msg from server in the client.
i Can send from client to server but wen i write from server, client does not read the message send. How to solve it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
void deliver(const chat_message& msg)
{
bool write_in_progress = !write_msgs_.empty();
write_msgs_.push_back(msg);
if (true)
{
boost::asio::async_write(socket_,
boost::asio::buffer(write_msgs_.front().data(),
write_msgs_.front().length()),
boost::bind(&chat_session::handle_write, shared_from_this(),
boost::asio::placeholders::error));
}
}
this is modified code of chat in Boost sample. I need to display from client in the server and msg from server in the client.
i Can send from client to server but wen i write from server, client does not read the message send. How to solve it?