// Server.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "afxsock.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	if (AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0) && AfxSocketInit())
	{
		CSocket TCP;
		TCP.Create(4900);
		if(TCP.Listen())
		{
			printf("Aguardando conexao!\r\n");
			CSocket conexao;
			TCP.Accept(conexao);
			printf("Conexao estabelecida!\r\n");
			while(true)
			{
				char buffer[10000];
				buffer[conexao.Receive(buffer,10000)]=0;
				if(strlen(buffer)==0)
					break;
				printf(buffer);
			}
			conexao.Close();
			printf("Conexão encerrada!\r\n");
		}
		TCP.Close();
	}
	return 0;
}



