# WinSock 2 Simple Client Program not Working

This topic is 4073 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

##### Share on other sites
struct addrinfo *result=NULL, *ptr=NULL, hints;.....ConnectSocket=socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol);

ptr == NULL

The rest of the initialization is fishy as well.

hints.ai_family=AF_UNSPEC;

This is usually AF_INET, although it probably doesn't need to be.

##### Share on other sites
That is something I didn't write myself so I guess it probably wouldn't be the case, I ripped it off from MSDN, so you know, nothing could create such a fatal error.

I'll try though, changing these values, and edit/post message to tell you what happened.

I would also like to know if there are any tutorials which can help me use winsock from console applications and not that window.h stuff.

As of now I did try to download VC++, the free edition, but it says it needs to download 94MB which I can't since I am running out of the amount of download I can do this month. I have a feeling that the compiler, ie Dev-C++ might be the thing causing problems.

EDIT: Nothing that I could change much, my program still doesn't work.
EDIT: Szome corrections of stupid things fixed it, i am sorry for being a little n00bish and not seeing the code earlier. The things were like some errors in If statements and stuff like that fixed it. Thanks for the help anyway, since now I'll use INET insted of UNSPEC

[Edited by - DrCoolSanta on July 26, 2007 8:08:52 AM]

##### Share on other sites
I'll assume this is the example you're referring to.

What happens if you copy that verbatim and compile it?

It's not an IDE problem, and given that this is the most basic winsock, it shouldn't be a compiler problem either.

When it comes to tutorials, there are small, but important differences between various platforms. And what exactly they are, given that winsock on dev-C++ (gcc), I don't really know which APIs get linked and how.

##### Share on other sites
A sockaddr_in struct is more helpful to me when working through connecting to a server, I usually end up with code like this :

//WSAStartup blah blah//socket structure propertiesstruct sockaddr_in SockAddr;SockAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); //connect to thyselfSockAddr.sin_port = htons(80); //which portSockAddr.sin_family = AF_INET;memset(SockAddr.sin_zero, 0, 8);SOCKET mysocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);connect(mysocket, (sockaddr*)&SockAddr, sizeof(SockAddr));//to quit the socket you shut it downshutdown(mysocket, 2);closesocket(mysocket);WSACleanup();

[Edited by - TheyDontCallMeMatt on July 26, 2007 10:21:53 AM]

##### Share on other sites
Thank you TheyDontCallMeMatt, I'll probably use that when I am doing something more serious, right now I'll stick to addrinfo, because MSDN doesn't explaing much, how it works.

Antheus, as I said earlier, I have fixed it, don't worry, it was just some silly mistakes. And actually that wasn't the example look for the Basic Code and stuff.

1. 1
2. 2
Rutin
22
3. 3
4. 4
frob
16
5. 5

• 9
• 33
• 13
• 13
• 10
• ### Forum Statistics

• Total Topics
632580
• Total Posts
3007188

×