IP Address
My winsock client that i gave to somebody on another LAN network won't work. I know it is a problem with the ip address. I tried to connect using my global ip, but it didn't work, and then i gave him the client that connects with the local ip and it still didn't work. Here is the conflicting (especially look at the sockaddr_in structure) code:
Ooops, I forgot to mention that I already did port forwarding, and it still didn't work.
Code:
int SendFullScoreReport(char* buffer)
{
WSAData wsa;
SOCKET sock;
if(WSAStartup(MAKEWORD(2,2), &wsa) != 0)
{
cout<<"An error has occured trying to initialize WinSock.";
WSACleanup();
cin.get();
return 0;
}
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(sock == INVALID_SOCKET)
{
cout<<"Socket is invalid.";
WSACleanup();
cin.get();
return 0;
}
struct hostent *host;
if((host=gethostbyname("localhost"))==NULL)
{
std::cout<<"Failed to resolve hostname.\r\n";
WSACleanup();
system("PAUSE");
return 0;
}
SOCKADDR_IN sockaddr;
sockaddr.sin_family = AF_INET;
sockaddr.sin_port = htons(8888);
sockaddr.sin_addr.S_un.S_addr = inet_addr("xx.xx.xx.47");
if(connect(sock, (SOCKADDR*) &sockaddr, sizeof(sockaddr)) != 0)
{
cout<<"Failed to connect to server.";
WSACleanup();
cin.get();
return 0;
}
cout<<"\nSending the full score report.";
send(sock, "Print", 5, 0);
Sleep(1000);
send(sock, buffer, strlen(buffer), 0);
cout<<"\nThe Full Score Report has been successfully sent.\n";
closesocket(sock);
WSACleanup();
system("PAUSE");
return 0;
}
Ooops, I forgot to mention that I already did port forwarding, and it still didn't work.
