Reply1: It was not a good question, I found an online eBook in my mother tongue language and it helped a lot for me.
Reply2: In Dev we need to add libraries in two places; one in project options-->Parameters and the other is Tools--> Compiler Options--> Directories. I got that the libraries are in the installation path of my Dev software.
Reply3: DO NOT USE DEV while you are using windows dll, specially in Win7. It does not work at all!!!
Please use another compiler ....
Reply4: (corrected)--> This below code will be built in Dev but does not run properly so that it is not a practical example.
Collapse | Copy Code
#include < stdio.h>
#include < conio.h>
#include < stdlib.h>
#include < string.h>
#include < winsock2.h>
int main(int argc,char **argv){
WSADATA wsaData;
WORD wVersionRequested;
SOCKET intSocket;
struct sockaddr_in recSin;
int intErr;
char *pchrBuffer;
if(argc<=2){
printf("::Error on the Call Program::\n");
printf("%s RemoteIPAddress RemotePort",argv[0]);
exit(1);
}
recSin.sin_addr.S_un.S_addr=inet_addr(argv[1]);
recSin.sin_family=AF_INET;
recSin.sin_port=htons(atoi(argv[2]));
wVersionRequested=MAKEWORD(2,0);
if(WSAStartup(wVersionRequested,&wsaData)){
printf("\n::Error on the INET Socket::\n");
exit(1);
}
intSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
if(intSocket==INVALID_SOCKET){
printf("\n::Error on Create the Socket::\n");
WSACleanup();
exit(1);
}
intErr=connect(intSocket,(struct sockaddr *)&recSin,sizeof(recSin));
if(intErr==INVALID_SOCKET){
printf("\n::Error on Connect to the Socket::\n");
WSACleanup();
exit(1);
}
pchrBuffer="HI\0";
intErr=send(intSocket,pchrBuffer,strlen(pchrBuffer),0);
if(intErr==SOCKET_ERROR){
printf("\n::Error on the Data Send::\n");
printf("Error Code:%d",WSAGetLastError());
WSACleanup();
exit(1);
}
memset(pchrBuffer,'\0',strlen(pchrBuffer));
if(intErr==SOCKET_ERROR){
printf("\n::Error on the Data Receive::\n");
printf("Error Code:%d",WSAGetLastError());
exit(1);
}
printf("\nData Received:%s\n",pchrBuffer);
closesocket(intSocket);
WSACleanup();
getch();
}
[edit]code block added[/edit]