SkinnyDragon
Technical User
Hello guys, I am new to programming. Well what I want to create is a small program similar to microsoft's instant messenger. Although I know at the momenet I cant create nothing as advance as that but i just want a simple messenger app. I created a wisock app. But it would not compiled correctly. I know that sometimes different compliers uses differnt header names. Do Visual C++ uses <winsock.h>, or somthing different. If you dont mind to look over my code, here it is. Thanks guys. 
include <winsock.h>
/* code to establish a socket
*/
SOCKET establish(unsigned short portnum)
{ char myname[256];
SOCKET s;
struct sockaddr_in sa;
struct hostent *hp;
memset(&sa, 0, sizeof(struct sockaddr_in)); /* clear our address */
gethostname(myname, sizeof(myname)); /* who are we? */
hp = gethostbyname(myname); /* get our address info */
if (hp == NULL) /* we don't exist !? */
return(INVALID_SOCKET);
sa.sin_family = hp->h_addrtype; /* this is our host address */
sa.sin_port = htons(portnum); /* this is our port number */
s = socket(AF_INET, SOCK_STREAM, 0); /* create the socket */
if (s == INVALID_SOCKET)
return INVALID_SOCKET;
/* bind the socket to the internet address */
if (bind(s, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) ==
SOCKET_ERROR) {
closesocket(s);
return(INVALID_SOCKET);
}
listen(s, 3); /* max # of queued connects */
return(s);
}
include <winsock.h>
/* code to establish a socket
*/
SOCKET establish(unsigned short portnum)
{ char myname[256];
SOCKET s;
struct sockaddr_in sa;
struct hostent *hp;
memset(&sa, 0, sizeof(struct sockaddr_in)); /* clear our address */
gethostname(myname, sizeof(myname)); /* who are we? */
hp = gethostbyname(myname); /* get our address info */
if (hp == NULL) /* we don't exist !? */
return(INVALID_SOCKET);
sa.sin_family = hp->h_addrtype; /* this is our host address */
sa.sin_port = htons(portnum); /* this is our port number */
s = socket(AF_INET, SOCK_STREAM, 0); /* create the socket */
if (s == INVALID_SOCKET)
return INVALID_SOCKET;
/* bind the socket to the internet address */
if (bind(s, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) ==
SOCKET_ERROR) {
closesocket(s);
return(INVALID_SOCKET);
}
listen(s, 3); /* max # of queued connects */
return(s);
}