🎉 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!

ACKPTH! WinSock logic error??

Started by
0 comments, last by WebSpyder 23 years, 10 months ago
My WinSock program just doesn''t want to stop giving me problems. I''m making a client-server app but the problem is this: The server opens and binds to a port right? Then it listens. OK. Now the client tries to connect, it says its connected and sends data. Right when it sends data (we had the two screens side-by-side) the server says it has refused the connection (accept() failed) and THEN the client spits out that it has recieved info (just the un-initialized buffer). I think its a logic error somewhere along the line cause the code looks fine!! Here are the functions: SERVER SIDE the accept function:
    
SOCKET client;
sockaddr*	client_sock;	// address of our client socket


// upon picking up a request, accept it and connect using the 
// client socket	

int lenclient = sizeof(client_sock);

if (client = accept(hSock, client_sock, &lenclient))
{
  // on error, display message, cleanup and quit
  cout << "Socket did not connect!" << WSAGetLastError() << endl;
  WSACleanup();
  return(0);
}
[/source]

CLIENT SIDE

the connect function:
[source]
// fill in the sockaddr_in struct

target.sin_family = PF_INET;	// our socket family (TCP\IP)
target.sin_port	= htons(5000);	// our port (5000)
target.sin_addr.s_addr	= inet_addr(ANY); // the server IP addr


// now connect to the listening socket on our server

if (connect(localSock, (LPSOCKADDR)⌖, sizeof(target)) == SOCKET_ERROR)
{
  // on error, print message, cleanup and quit
  cout << "Socket could not connect to server: " << WSAGetLastError() << endl;
  WSACleanup();
  return(0);
}
    
can you see any kind of logical error in there? If not, do you have any idea why its acting like this? If you need to see more code, let me know and i''ll post it. Peace. ****************************** "I do not fear computers, I fear the lack of them" - Isaac Asimov Drew Sikora Napali Networks, Inc.
******************************"I do not fear computers, I fear the lack of them" - Isaac AsimovDrew SikoraNapali Networks, Inc.
Advertisement
Where you have:
if (Client = accept...) {...}

change it to:
Client = accept (...)
if (Client == INVALID_SOCKET)
{ /* error */ }

That should fix one of your issues

-BacksideSnap-

This topic is closed to new replies.

Advertisement