Sign in to follow this  
twelfth

ERROR: WSARecv the socket returned from accept with code 10038

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this