🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Needing Some Winsock2 Help

Started by
7 comments, last by Xienen 23 years, 2 months ago
Alright...I''m having trouble with my code, I mean, it compiles, but doesnt run...and I don''t mind just posting my code up for everyone to see, so here goes: Server App(Only Winsock Stuff Shown): int ClientCount; sockaddr_in Server; SOCKET ConnectSock; SOCKET Client_Sock[MAX_CLIENTS]; sockaddr Client_Addr[MAX_CLIENTS]; main() { ClientCount = 0; ConnectSock = socket (AF_INET,SOCK_STREAM,0); Server.sin_family = AF_INET; Server.sin_port = htons (1526); Server.sin_addr.s_addr = htonl (INADDR_ANY); bind(ConnectSock,(LPSOCKADDR)&Server,sizeof(Server)); listen(ConnectSock,5); //This is the part that just sits there, i know it runs up to //this point, but it just stops and never goes past this Client_Sock[Count] = accept(ConnectSock, &Client_Addr[Count], &addr_size); } ClientSide App: SOCKET ASocket; ASocket = socket(AF_INET, SOCK_STREAM, 0); WSAAsyncSelect(ASocket, hWnd, WM_SOCKET, FD_READ | FD_CONNECT | FD_CLOSE); sockaddr_in target; target.sin_family = AF_INET; target.sin_port = htons(1526); target.sin_addr.s_addr = inet_addr ("66.56.58.5"); connect(ASocket, (LPSOCKADDR)⌖, sizeof(target)); //Connect functions returns Error 0 when I call WSAGetLastError(); if anyone can give me any insight, it would be most appreciated. -= Xienen =- -= C++ Lead Programmer =- -= http://www.galaxysoldiers.net =-
-= Dayle Flowers =--= Senior Engine and Gameplay Programmer =-
Advertisement
You might have a typeo Count is not defined...

Anywhoo..
Make sure the accept counter is works..
------------------------------------------------------------I wrote the best video game ever, then I woke up...
Well, Count is an integer that is Global, and the accept seems to work, because I made a cout command right before the accept command to test it, and it runs, so it seems that it runs just fine, and since the server app is running off of blocking sockets, it just stays in accept mode until it receives a connection, but it never receives a connection, because I made a cout command after accept() and it never gets printed to the screen.

-= Xienen =-
-= C++ Lead Programmer =-
-= http://www.galaxysoldiers.net =-
-= Dayle Flowers =--= Senior Engine and Gameplay Programmer =-
Is there a firewall blocking the connection? I run zonealarm and you have to allow the program to make a connection.

-ddn
Thanx for the idea, but no, there is not a firewall setup on either of the computers that I tested.

-= Xienen =-
-= C++ Lead Programmer =-
-= http://www.galaxysoldiers.net =-
-= Dayle Flowers =--= Senior Engine and Gameplay Programmer =-
Try running both programs on the same computer and connect to the localhost (127.0.0.1) instead of the (dynamic?) IP you''re currently connecting to. Haven''t tested this because I currently don''t have access to C++. Good luck.

Jasper
Well...it works, thank you, but what does that mean? Why won''t it connect to external computers then?
-= Dayle Flowers =--= Senior Engine and Gameplay Programmer =-
i can send you a source i just wrote for a tcp chat tutorial that i''m going to write soon, maybe the source will help you see what''s wrong in your code altough i didn''t see anything wrong

i don''t get why it doesn''t connect to external computers, maybe yer connections is slow and the timeout is short ?

Arkon
http://qsoft.cjb.net
Maybe your not on the same subnet as the other computer? If your on a LAN and you don''t have any routing going on you need to set the first three parts of the IPs to be the same.

Example:
Server IP: 192.168.0.1
Client IP: 192.168.0.2

I did not look at the code but since it works if you use a local IP I think that the problem is the network, not the code. Just make sure that the computers can reach eachother. Try pinging them.

-Benny-

This topic is closed to new replies.

Advertisement