i ran into some C++ WINSOCK programming codes and i thought i should give it a try . i wanted to make a chat program but first i had to try it on my own before i went looking for help and i came across this at msdn
#include <stdio.h>
#include "winsock2.h"
int main() {
WSADATA wsaData;
SOCKET SendSocket;
sockaddr_in RecvAddr;
int Port = 27015;
char SendBuf[1024];
int BufLen = 1024;
//---------------------------------------------
// Initialize Winsock
WSAStartup(MAKEWORD(2,2), &wsaData);
//---------------------------------------------
// Create a socket for sending data
SendSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
//---------------------------------------------
// Set up the RecvAddr structure with the IP address of
// the receiver (in this example case "123.456.789.1")
// and the specified port number.
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(Port);
RecvAddr.sin_addr.s_addr = inet_addr("123.456.789.1");
//---------------------------------------------
// Send a datagram to the receiver
printf("Sending a datagram to the receiver...\n");
sendto(SendSocket,
SendBuf,
BufLen,
0,
(SOCKADDR *) &RecvAddr,
sizeof(RecvAddr));
//---------------------------------------------
// When the application is finished sending, close the socket.
printf("Finished sending. Closing socket.\n");
closesocket(SendSocket);
//---------------------------------------------
// Clean up and quit.
printf("Exiting.\n");
WSACleanup();
return 0;
}am using Dev-C++ 4.9.9.2 compiler, when i compile it i get these errors
[Linker error] undefined reference to `WSAStartup@8' [Linker error] undefined reference to `socket@12' [Linker error] undefined reference to `htons@4' [Linker error] undefined reference to `inet_addr@4' [Linker error] undefined reference to `sendto@24' [Linker error] undefined reference to `closesocket@4' [Linker error] undefined reference to `WSACleanup@0' ld returned 1 exit status C:\Dev-Cpp\New Folder (2)\Makefile.win [Build Error] [Project2.exe] Error 1
any help will b greatly appreciated...thx

Help


Back to top









