I have a question regarding asynchronous sockets. I have a server and client application. The client selects a file and that file should be transmitted to the server. The client connects to the server starts reading the file and transmits its contents, the problem is how on the server side do I collect them? What I mean is that in case of asynchronus sockets the server is notified only when there is data to be recieved, in such a case recv () is thus non blocking, then how do i determine from where is the data coming? And how do I collect it?

On the server side I start a thread everytime a client connects but the recv () being non blocking immediately goes out and the thread ends. I tried something like this:
Code:
//The message handler which is called each time there is data to be recieved
HRESULT CASyncServerDlg::OnSocket (WPARAM wParam, LPARAM lParam)
{
	sockaddr_in from;
	int len = sizeof (from);
	SOCKET client;
	TCHAR buffer [MAX_PATH];
	if (LOWORD (lParam) == FD_ACCEPT)
	{
		client= accept (server,
			(struct sockaddr*)&from, &len);
		sprintf (buffer, "Message from server! You are connected!");
		send (client, buffer, _tcslen (buffer), 0);
		AfxBeginThread (ClientThread, (LPVOID)client);
	}
/*
	if (LOWORD (lParam) == FD_READ)
	{
		int nRet = recv ((SOCKET)wParam, buffer, MAX_PATH, 0);
		buffer [nRet] = 0;
		m_ListBox.AddString (buffer);
	}
*/
	return 0;
}

//The thread function
UINT CASyncServerDlg::ClientThread (LPVOID pParam)
{
	SOCKET client = (SOCKET)pParam;
	TCHAR buffer [MAX_PATH];
	CFile file;
	file.Open ("C:\\file.dat", CFile::modeWrite | CFile::modeCreate);
	int nRet = recv (client, buffer, MAX_PATH, 0);
	do
	{
		file.Write (reinterpret_cast<void *>(buffer), MAX_PATH);
		nRet = recv (client, buffer, MAX_PATH, 0);
	}
	while (nRet > 0);
	file.Close ();
	return 0;
}
Iam quite perplexed, looking for some directions now...

Regards.