Connection refused

Hi there,

Anything will help.

I have running server on computer and want to connect from some clients.

Server:
memset(&hints, 0, sizeof(hints));
hints.ai_family = domain;
hints.ai_socktype = SOCK_STREAM;

error = getaddrinfo("localhost", "8300", &hints, &res0);
if (error)
{
return false;
}

for (res = res0; res; res = res->ai_next)
{
socket_d = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
int result = bind(socket_desc, (const sockaddr *) res->ai_addr, res->ai_addrlen);
}

And I want to connect from some client:

memset(&hints, 0, sizeof(hints));
hints.ai_family = PF_UNKNOWN;
hints.ai_socktype = SOCK_STREAM;

error = getaddrinfo("195.113.21.133", "8300", &hints, &res0);

if (error)
{
return false;
}

for (res = res0; res; res = res->ai_next)
{
socket_d = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
int result = connect(socket_d, res->ai_addr, res->ai_addrlen);
}

When I put "localhost" in getaddrinfo everything is fine. But when I tried to put some other IP, it crashes. IP is correct, both computers are on same network.

THX for any advice!

Hello,

The socket() call should be made on the localhost, which means that you wnat to create a socket on the localmachine

In the connect() call, mention the address of the server which you want to connect.

and on the server side, after socket and bind, listen and accept functions should be called for listening and accepting socket from the client.

Regards
Gaurav