Boost Asio acceptor won't accept client connections

I am new to socket programming and have just started coding with Boost's Asio library. What my program intends to do is send the message "Hello World!" from the server to the client but server doesn't accept client connections and therefore the client isn't able to make a connection. I have a feeling the problem is on the server's side. Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//client.cpp
#include <boost/asio.hpp>
#include <boost/bind.hpp>

#include <iostream>


boost::asio::io_service io;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::address::from_string(ip_address), 995);
boost::asio::ip::tcp::socket a_socket(io);
char buffer[64];

void start_read();
void handle_read(const boost::system::error_code&, size_t);

int main(){
	try{
		a_socket.connect(endpoint);
		
		start_read();
		
		for(;;){
			io.run();
		}
	}
	catch(std::exception &e){
		std::cout << e.what();
	}
	
	return 0;
}

void start_read(){
	boost::asio::async_read(a_socket, boost::asio::buffer(buffer), &handle_read);
}

void handle_read(const boost::system::error_code&, size_t){
	std::cout << buffer;
	
	a_socket.close();
}


I named the socket a_socket because the name socket had some sort of name conflict. This is the server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <boost/asio.hpp>
#include <boost/bind.hpp>

#include <iostream>

boost::asio::io_service io;
boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(), 995);
boost::asio::ip::tcp::acceptor acceptor(io, endpoint);

void start_accept();
void handle_accept();

int main(){
	try{
		for(;;){
			boost::asio::ip::tcp::socket socket(io);
			std::cout << 1;
		
			acceptor.accept(socket);
			std::cout << 2;
			
			boost::asio::write(socket, boost::asio::buffer("Hello world!", 13));
			std::cout << 3;
			
			socket.close();
		}
	}
	catch(std::exception &e){
		std::cerr << e.what() << "\n";
	}
	
	return 0;
}

So on the server, the program is stuck at acceptor.accept(socket) and I can't figure out why. I've been searching hours on how to solve this so now I'm going asking on this forum. I made sure that port 995 was forwarded correctly.
What is ip_address? Is the address resolved correctly?

boost recommends to use make_address().
ip_address
was just a generic variable name for the string representation of the ip address. Thanks for the response. I found the problem of the issue eventually and it did indeed have something to do with the address not being resolved correctly. It seemed that the local ip address has to be used for the server application and the also the client if on the same computer. But the WAN address is to be used on all other computers.
Topic archived. No new replies allowed.