Can someone please explain to me what I'm doing wrong... From what I can see, there is nothing wrong with my code. The server is supposed to send me 3 integers as a response, but the problem is it never even connects, the call to connect prints "connect error" every time... Thanks:
Code:#include <iostream> #include <Winsock2.h> #define ADDRESS "69.55.233.82" #define PORT 5842 using namespace std; int main() { WSADATA wsaData; sockaddr_in serv; SOCKET sock; if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { printf("WSAStartup error"); exit(1); } sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); serv.sin_family = AF_INET; serv.sin_addr.S_un.s_addr = inet_addr(ADDRESS); serv.sin_port = htons(PORT); if (connect(sock,(sockaddr *)&serv, sizeof(serv)) == SOCKET_ERROR) { printf("connect error"); WSACleanup(); exit(1); } int a = 0, b = 0, c = 0; recv(sock, (char *)&a, sizeof(unsigned int), 0); recv(sock, (char *)&b, sizeof(unsigned int), 0); recv(sock, (char *)&c, sizeof(unsigned int), 0); printf("int a: %d\nint b: %d\nint c: %d", a, b, c); closesocket(sock); WSACleanup(); }



LinkBack URL
About LinkBacks


