Jump to content
  • Advertisement
Sign in to follow this  

Winsock inside a service problem

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Outputdebug does NOT work. I must have like 20 of them in my service and I never get to see one in visual studio.I'll try what endurion said.


Not sure if debugview doesn't work or I'm not using it the right way...i see nothing in the list

Edited by noatom

Share this post

Link to post
Share on other sites

I'd go for a logfile then. C:\out.txt or something like that.


Do breakpoints work? You probably want to narrow the problem down a bit before you start stepping through code though.

Share this post

Link to post
Share on other sites
void CSampleService::ServiceWorkerThread(void)

    // Periodically check if the service is stopping.
	FILE* pFile = fopen("logFile.txt", "a");
    fprintf(pFile, "%s\n","In worker function");
    while (!m_fStopping)

	SOCKADDR_IN SenderInfo;
	SOCKET NewConnection;

	int ClientLen = sizeof(SOCKADDR_IN);
	SOCKADDR_IN ClientAddr;

	int ByteReceived, nlen;
	char recvbuff[1024];
		// Main program loop
		NewConnection = SOCKET_ERROR;
		if(NewConnection == SOCKET_ERROR) 
			//NewConnection = accept(ListeningSocket, NULL, NULL);	// this is a blocking function
			NewConnection = accept(ListeningSocket,(SOCKADDR*)&ClientAddr, &ClientLen);
			OutputDebugString(L"New client got connected, ready to receive and send data...\n\n");
			ByteReceived = recv(NewConnection, recvbuff, sizeof(recvbuff), 0);

			if (ByteReceived > 0) 
				fprintf(pFile, "%s\n","Received bytes!");
				getsockname(ListeningSocket, (SOCKADDR *)&ServerAddr, (int *)sizeof(ServerAddr));

				memset(&SenderInfo, 0, sizeof(SenderInfo));
				nlen = sizeof(SenderInfo);

				getpeername(NewConnection, (SOCKADDR *)&SenderInfo, &nlen);	

		if (shutdown(NewConnection, 2) != 0)
			OutputDebugString(L"Line 355");
			OutputDebugString(L"shutdown is working...\n");


    // Signal the stopped event.

So,see that ServStart() call at the begining,it turns out it calls that function(saw it on a logfile),but after it gets out of it,it doesn't to anything.I mean when it gets out it should post some of those lines of text,but it doesn't.


Why would the call to StartServer do fine,and after that "nothing happens" ?

Share this post

Link to post
Share on other sites

Print more stuff to the file. You are still using OutputDebugString as well...


Does accept() ever return? You can probably just put a breakpoint on the OutputDebugString following to see if it does.


When tracing I usually log




at the start of each function and




everywhere it returns/exits, along with other information, especially before and after calls to blocking functions...

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!