Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.
Cant connect to server with d c++
I've never did much c++ programing before, so i am trying to setup a socket connection with a server, so i can send data to it (chat server)
this is what I'm trying, but i keep getting these errors, it just relates to the networking part:
ERRORS:
[Linker error] undefined reference to `WSAStartup@8'
[Linker error] undefined reference to `socket@12'
[Linker error] undefined reference to `gethostbyname@4'
[Linker error] undefined reference to `htons@4'
[Linker error] undefined reference to `connect@12'
ld returned 1 exit status
CODE TRIED:
WSADATA wsaData;
SOCKET hSocket;
SOCKADDR_IN sIn;
LPHOSTENT serverName;
char sndBuffer[256];
char recvBuffer[256];
WSAStartup(MAKEWORD(2, 2), &wsaData);
hSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
serverName = gethostbyname("www.spinchat.com");
sIn.sin_family = AF_INET;
sIn.sin_addr = *((LPIN_ADDR)*serverName->h_addr_list);
sIn.sin_port = htons(3001);
if(connect(hSocket, (sockaddr*)&sIn, sizeof(struct sockaddr)) == SOCKET_ERROR)
cout << "Error: Connection failed." << endl;
// connected
Please help…:(
Thanks for your helpful replies, I'm sure what you said is right, but I'm not there yet. I added the #pragma comment inclusion, then the same error cam up again, lol. I did what Zero said and went to the linker options, there was one option:
Link an objective program: NO
I then changed it to YES, tehn a weird error came up when I compiled:
Cannot find -lobjc
ID returned exit status 1
At least all those errors have gone, but now it says it can't find the -lobjc, whatever that is. :|