Originally Posted by
Salem
> the code that is given in this tutorial is supposed to be written for Visual C++ 6.0 standard edition
It pretends to be C, but it takes C++ to compile it
It's also crap code.
Not only does it lack formatting, 3 out of the first 4 lines are sloppy and or wrong.
Assuming the following is the code he is trying to compile:
Code:
#include "stdio.h"
#include "winsock.h"
#define PORT 1200
void main(int argc,char *argv[]){
WSADATA wsda;
WSAStartup(0x0101,&wsda);
struct sockaddr_in server;
int sockfd;
struct hostent *h;
char *message="Hello Server";
if(argc!=2){
printf("Usage : client ");
exit(1);
}
if((sockfd=socket(AF_INET,SOCK_STREAM,0))==-1){
printf("Socket Error...");
exit(1);
}
if((h=gethostbyname(argv[1]))==NULL){
fprintf(stderr,"Host Name Error...");
exit(1);
}
server.sin_addr=*((struct in_addr*)h->h_addr);
server.sin_port=htons(PORT);
server.sin_family=AF_INET;
if(connect(sockfd,(struct sockaddr*)&server,sizeof(struct sockaddr))==-1){
fprintf(stderr,"Connection out...");
exit(1);
}
send(sockfd,message,strlen(message),0);
WSACleanup();
closesocket(sockfd);
}
Where do you see C++ in this? Also where do you see wrong code here? (Not saying you are wrong in your statement that 3 out of the first 3 lines are sloppy/wrong, but at a glance, I dont see any wrong code here).