Advertisement

WSAError 10060 (Connection Timed out)

Started by April 29, 2005 03:19 AM
7 comments, last by John Schultz 19 years, 9 months ago
Ok, I have tracked this puppy down and got the error code of 10060 when returning the WSAErrorCode. Which means: Connection timed out. A connection attempt failed because the connected party did not properly respond after a period of time, or the established connection failed because the connected host has failed to respond. as quoted by MSN. Now I am at a complete loss here. As I know the IP address is correct, and on a machine in which the client fails to connect to the server residing on the IP address, I can ping the IP address just fine. Both Client and Server have the correct port binded in. Both using TCpIP. Server is up and running, and awaiting connections. Whats even stranger is if I use the same code ,just earlier version of the client, it connects just fine. No changes to the code. Also, the router I am behind is configured to allow the port to be opened. No firewalls are running on my computer. Any Suggestions or help please? :)
<=- Talon -=>
Quote:
Original post by TalonSnow
Both Client and Server have the correct port binded in. Both using TCpIP. Server is up and running, and awaiting connections.
Whats even stranger is if I use the same code ,just earlier version of the client, it connects just fine. No changes to the code.


If an older version of the client connects to the server OK, then something must have changed in the newer version of the client. Compare the old and new client code (use a diff tool if the code is complicated).
Advertisement
nope the network code is the exact same, very simple to connect. here is the client code.

#pragma once#include "stdafx.h"#include "globals.h"#include "winsock2.h"#include "engine.h"int init();int netReceive();int	nret;			//for error handling codeschar	errorNum[20];int init(){	WriteError("////  NETWORK INIT  ////");	// Must be done at the beginning of every WinSock program	WSADATA w;    // used to store information about WinSock version	int error = WSAStartup (0x0202, &w);   // Fill in w	if (error)	{ // there was an error		WriteError("ERROR: unable to start WSAStartup");		return 0;	}	WriteError("WSAStartup was SUCCESSFULL");	if (w.wVersion != 0x0202)	{ // wrong WinSock version!		WriteError("ERROR: Wrong WinSock version");		WSACleanup (); // unload ws2_32.dll		return 0;	}	WriteError("WinSock version was SUCCESSFULL");	// SOCKET s is a valid socket	// WSAStartup has been called	st = socket (AF_INET,SOCK_STREAM,IPPROTO_TCP);	//creating the socket	if(st == INVALID_SOCKET)	{		nret = WSAGetLastError();		_itoa(nret,errorNum,10);		WriteError(errorNum);		WSACleanup();		return 0;	}	WriteError("Socket created successfully");	target.sin_family = AF_INET;				//address family internet	target.sin_port = htons(2604);				//assigning port 2604 to socket	target.sin_addr.s_addr = inet_addr("66.189.178.131");  // set server’s IP	nret=connect(st, (LPSOCKADDR)&target, sizeof(struct sockaddr));	if(nret == SOCKET_ERROR)	{ // an error connecting has occurred!		nret = WSAGetLastError();		_itoa(nret,errorNum,10);		WriteError("ERROR: Unable to connect to Server");		WriteError(errorNum);		WSACleanup ();		return 0;	}	isConnect=true;	WriteError("Connecting to server was SUCCESSFULL");	unsigned long b=1;	ioctlsocket(st,FIONBIO,&b);	return 1;}


Globals
// globals for winsock and networkingSOCKET		st;sockaddr_in target;bool		isConnect=false;


could it be that i might have a memory leak that the cpu is too busy to try to connect? And if so, why would the client(new one) still connect just fine on my own computer on the server?
<=- Talon -=>
I suggest using Ethereal (free network sniffer) to figure out what packets go out and back in the case of the old, and new clients. Then look for differences.
enum Bool { True, False, FileNotFound };
mm... I am a complete novice when it comes to networking, and I cant make sense of Ethereal. I am doubting that you can explain how to just check what it is your askign me to also, as the program looks complex to me right now, unless you think you can explain just how to do what your asking simply :)

some random thoughts:

(1) would the client have any problems trying to connect in exclusive mode full windowed directX?
(2) Why would the client connect to the server on my own machine, when both running,(while client still using IP address not local host address) yet not on another computer on the network (router) when the "other" computer can still ping me?
(3) also noted the small client that was connecting to the server before is also not working now. This leads me to believe it was a change on the server that broke it not the client. (which makes more sense as the client code never changed)

*** Anyone interested in helping enough to email them the client and server networking code, and sift through it real fast? (Both are relatively very small)
<=- Talon -=>
Problem Solved!

it was the lines:
unsigned long b=1;
ioctlsocket(st,FIONBIO,&b);

in the server code on the thread that listened for a connection. I not sure why it fails, as to my understanding if there was nothing asking for a connection it just looped around again and tried to accept a connect again (which according to my logs from the server it was doing) but for some reason it was proceeding past the accept command even if someone was trying to connect.
Well anyways, once i commented out those two lines, it works just fine. Though if anyone could coorect me on my understanding of what i was doing wrong and why it wouldnt accept i would still appreciate the knowledge.
<=- Talon -=>
Advertisement
Quote:
Original post by TalonSnow
in the server code on the thread that listened for a connection.


Since it sounds like you have a specific thread waiting for connections, the socket should not be set to non-blocking, otherwise you'll waste a huge amount of CPU cycles doing nothing. When the socket is blocked, the thread yields (sleeps) until someone trys to connect. When unblocked, the thread will run using 100% of the CPU cycles (with the socket generating EWOULDBLOCK errors). This could be the reason for intermittant timeouts/failures.

Are you checking for errors after every socket call?

[Edited by - John Schultz on April 30, 2005 3:53:37 PM]
yes i am

Yeah thats the only way I could understand is if because it was using 100% cpu cycles, it wouldnt have time to process the connect. However, why would you ever use the function if you wont have the time to process it? Or do you have to put a sleep command after it, and even then would it do the trick?
<=- Talon -=>
Quote:
Original post by TalonSnow
yes i am

Yeah thats the only way I could understand is if because it was using 100% cpu cycles, it wouldnt have time to process the connect. However, why would you ever use the function if you wont have the time to process it? Or do you have to put a sleep command after it, and even then would it do the trick?


You would use a non-blocking socket when implementing a single-threaded server. If no new connections are present, the main thread continues other processing, with no wasted cycles.

If you are writing a real-time game application, you might consider rewriting your server code to use a single-threaded design (easier to develop/debug, most likely more efficient).

This topic is closed to new replies.

Advertisement