#define CONNECTION_PORT 35424
#define WINSOCK_MSG (WM_USER + 542)
#define NUMBER_BASE 16 // Use hex as base number
#define WINSOCK_VER MAKEWORD(2,2)
#define TCPSOCKET socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
// in function...
WSAStartup(MAKEWORD(1,1),&wsaDat);
// Make the sockets
listenSck = TCPSOCKET;
// Get the local IP address...
hostent *host;
host = gethostbyaddr("127.0.0.1",strlen("127.0.0.1"),AF_INET);
host->h_addr_list[0];
localAddr.s_addr = inet_addr(host->h_addr_list[0]);
delete host;
// Fill in sckAddr
memset(&sckAddr, 0, sizeof(sckAddr));
sckAddr.sin_addr.s_addr = htonl(INADDR_ANY);
sckAddr.sin_family = AF_INET;
sckAddr.sin_port = htons(CONNECTION_PORT);
// Bind and Listen
if(bind(listenSck, (LPSOCKADDR)&sckAddr, sizeof(struct sockaddr)) < 0);
{
};
if(listen(listenSck,8) < 0)
{
};
Winsock bind() question
Whenever I bind() a socket, I get an error. I have already called socket() on the SOCKET that I pass to bind, and I intend to make it listen() afterwards. I generally do this:
What error do you get? Use WSAGetLastError() and figure it out from that..
and just curious but why is WINSOCK_VER #defined to be version 2.2 then you use version 1.1 in WSAStartup? Not that I think it really matters, just interesting
and just curious but why is WINSOCK_VER #defined to be version 2.2 then you use version 1.1 in WSAStartup? Not that I think it really matters, just interesting
All else being equal, I don''t think delete host; is a particularly bright idea. According to the manpage, gethostbyaddr() may return a pointer to static memory, which is definitely _not_ on the heap, let alone allocated via new.
cu,
Prefect
cu,
Prefect
Widelands - laid back, free software strategy
First off, as for 2.2 and 1.1, I switched versions to see if that would help anything. I get the same result with both versions. As for the error number, I do not have it with me , but I can get it.<br><br>As for pointers, and the heap, and all of that stuff, I DO NOT UNDERSTAND ANY OF IT. It all confuses the hell out of me. If someone could tell me where I can find some information on pointers that a 14-year old could understand.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement