Jump to content
  • Advertisement
Sign in to follow this  
twelfth

ERROR: WSARecv the socket returned from accept with code 10038

This topic is 5043 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

invalid socket? but it is returned from accpet() call. there are my code: Edited by hplus0603: added CODE tags
WSADATA wsad;
	if(WSAStartup(MAKEWORD(2, 2), &wsad) != 0)
	{
		// error handle
		return;
	}

	SOCKET server_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(server_socket == INVALID_SOCKET)
	{
		// error handle
		return;
	}

	// bind & listen
	SOCKADDR_IN addr;
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = INADDR_ANY;
	addr.sin_port = htons(8888);	// some port
	if(bind(server_socket, (SOCKADDR*)&addr, sizeof(addr)) == SOCKET_ERROR)
	{
		closesocket(server_socket);
		return;
	}

	if(listen(server_socket, 5) == SOCKET_ERROR)
	{
		closesocket(server_socket);
		return;
	}

	SOCKET client_socket = INVALID_SOCKET;//WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);

	// accept
	SOCKADDR_IN	client_addr;
	ZeroMemory(&client_addr, sizeof(client_addr));
	int addr_len = sizeof(client_addr);
	client_socket = accept(server_socket, (SOCKADDR*)&client_addr, &addr_len);
	if(client_socket == INVALID_SOCKET)
	{
		int err_code = WSAGetLastError();
		return;
	}

	// recv
	WSABUF buf;		// temp buf, just for demo
	buf.buf = new char[1024];
	buf.len = 1024;
	DWORD num_of_bytes = 0;
	DWORD flags	= 0; 
	OVERLAPPED op;	// io completion port, so there are nothing in it
	// post a recv
    if(WSARecv(client_socket, &buf, 1, &num_of_bytes, &flags, &op, NULL) == SOCKET_ERROR)
	{
		int err_code = WSAGetLastError();	// err_code is 10038, here!!!
		if(err_code != WSA_IO_PENDING)
		{
			// error handle
			return;
		}
	}
What is wrong ? [Edited by - hplus0603 on September 2, 2004 11:49:52 AM]

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!