Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual C++... Please help

Status
Not open for further replies.

SkinnyDragon

Technical User
Jan 7, 2002
1
US
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);
}

 
I may not necessarily be the one to help you, but if you can provide the specific error messages you are getting, it can help us to better diagnose your problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top