I'm implementing a simple client-server program. Some parts of the i wrote is:
int main(void){
using namespace boost::asio;
using namespace std;
const std::string ip = "localhost";
const int port = 10500;
ip::address addr = ip::address::from_string(ip);
ip::tcp::endpoint ep(addr, port);
ip::tcp::iostream s(ep);
s << "TERMINATE\n" << std::flush;} //This sends Terminate command to the server.
}
void function(void){
s << "TERMINATE\n" << std::flush;} // This part doesn't work.
}
I'm new to the boost asio and network programming. And working on windows MingGW.
As in the code above i declared the ip address in the main function, but when i try to use it in other functions declared outside of main it doesnt work. Comes with an error like: 's' was not declared in this scope. If it was a normal variable I'd declare it outside of the main and all of the other functions can share. But that would not work for this. Where and how do you need to declare the ip address and port. I'm assuming
using namespace boost::asio;
using namespace std;
const std::string ip = "localhost";
const int port = 10500;
ip::address addr = ip::address::from_string(ip);
ip::tcp::endpoint ep(addr, port);
ip::tcp::iostream s(ep);
above part is doing the declaration.