-1
I’m a beginner in c++ and I’m having trouble getting my client code to establish a connection with my server in Python, the server is working, but the client always enter error 4 and does not complete the connection, what should I do?
#include<winsock.h>
#include<string>
#include<iostream>
#include<vector>
#include<fstream>
SOCKET s;
int contador = TRUE;
int main()
{
while ( contador )
{
int minhaPorta = 5000;
char meuHost = '127.0.0.1';
WSADATA wsadata;
int error = WSAStartup(0x0202, &wsadata);
if (error)
{
std::cout<< "erro 1";
contador=FALSE;
}
if (wsadata.wVersion != 0x0202)
{
WSACleanup();
std::cout<<"erro 2";
contador=FALSE;
}
SOCKADDR_IN target;
target.sin_family = AF_INET;
target.sin_port = htons (minhaPorta);
target.sin_addr.s_addr = inet_addr (&meuHost);
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s == INVALID_SOCKET)
{
std::cout<<"erro 3";
contador=FALSE;
}
//Try connecting...
if (connect(s, (SOCKADDR *)&target, sizeof(target)) == SOCKET_ERROR)
{
std::cout<<"erro 4";
contador=FALSE;
}
else
{
std::cout<<"acerto 1";
contador=TRUE;
}
}
}
void CloseConnection ()
{
if (s)
std::cout<<"entrou aqui ";
closesocket(s);
WSACleanup();
}
Your machine is Ipv6 or Ipv4?
– lemoce
she is relatively young, has Ipv6 already
– IgorGPV
you should not be having "error 4" because this code neither compiles...
– zentrunix