Click here to Skip to main content
15,887,596 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionConnect to Remote Server Pin
mesajflaviu5-May-10 21:02
mesajflaviu5-May-10 21:02 
AnswerRe: Connect to Remote Server Pin
Richard MacCutchan5-May-10 21:31
mveRichard MacCutchan5-May-10 21:31 
AnswerRe: Connect to Remote Server Pin
Michel Godfroid5-May-10 21:32
Michel Godfroid5-May-10 21:32 
AnswerRe: Connect to Remote Server Pin
Moak5-May-10 21:34
Moak5-May-10 21:34 
GeneralRe: Connect to Remote Server Pin
mesajflaviu5-May-10 21:47
mesajflaviu5-May-10 21:47 
GeneralRe: Connect to Remote Server Pin
mesajflaviu6-May-10 5:22
mesajflaviu6-May-10 5:22 
GeneralRe: Connect to Remote Server Pin
Moak6-May-10 7:22
Moak6-May-10 7:22 
GeneralRe: Connect to Remote Server [modified] Pin
mesajflaviu6-May-10 5:39
mesajflaviu6-May-10 5:39 
Here is my entire code :

SOCKET CSmtp::ConnectRemoteServer(CString sServer, UINT nPort)
{
	short nProtocolPort;
	LPHOSTENT lpHostEnt;
	LPSERVENT lpServEnt;
	SOCKADDR_IN sockAddr;
	SOCKET hServerSocket = INVALID_SOCKET;
	struct in_addr addr;

	// If the user input is an alpha name for the host, use gethostbyname()
	// If not, get host by addr (assume IPv4)

	if(atoi(sServer.Left(1)) == 0)lpHostEnt = gethostbyname(sServer);
	else
	{
		addr.s_addr = inet_addr(sServer);
		if(addr.s_addr == INADDR_NONE)
		{
			m_nError = CSMTP_BAD_IPV4_ADDR;
			return INVALID_SOCKET;
		}
		else lpHostEnt = gethostbyaddr((char *)&addr,4,AF_INET);
	}

	if(lpHostEnt != NULL)
	{
		if((hServerSocket = socket(PF_INET,SOCK_STREAM,0)) != INVALID_SOCKET)
		{
			if(nPort)nProtocolPort = htons(nPort);
			else
			{
				lpServEnt = getservbyname("mail",0);
				if(lpServEnt == NULL)nProtocolPort = htons(25);
				else nProtocolPort = lpServEnt->s_port;
			}

			sockAddr.sin_family = AF_INET;
			sockAddr.sin_port = nProtocolPort;
			sockAddr.sin_addr = *((LPIN_ADDR)*lpHostEnt->h_addr_list);
			if(connect(hServerSocket,(PSOCKADDR)&sockAddr,sizeof(sockAddr)) == SOCKET_ERROR)
			{
				m_nError = CSMTP_WSA_CONNECT;
				hServerSocket = INVALID_SOCKET;
			}
		}
		else
		{
			m_nError = CSMTP_WSA_INVALID_SOCKET;
			return INVALID_SOCKET;
		}
	}
	else
	{
		m_nError = CSMTP_WSA_GETHOSTBY_NAME_ADDR;
		return INVALID_SOCKET;
	}

	return hServerSocket;
}


and here I try :
// connecting to remote host
CString sServer = "smtp.gmail.com";
if((m_hSocket = ConnectRemoteServer(sServer,25)) == INVALID_SOCKET)
{
    m_nError = CSMTP_WSA_INVALID_SOCKET;
    return FALSE;
}


modified on Thursday, May 6, 2010 12:13 PM

QuestionIs it safe to load dll compiled in Visual studio 2005 into application compiled in the Visual studio 6? Pin
PrafullaShirke275-May-10 19:52
professionalPrafullaShirke275-May-10 19:52 
AnswerRe: Is it safe to load dll compiled in Visual studio 2005 into application compiled in the Visual studio 6? Pin
Xing Chen5-May-10 20:10
Xing Chen5-May-10 20:10 
AnswerRe: Is it safe to load dll compiled in Visual studio 2005 into application compiled in the Visual studio 6? Pin
Rolf Kristensen6-May-10 11:19
Rolf Kristensen6-May-10 11:19 
Questionhow to call srand(time(NULL)); Pin
mrby1235-May-10 18:59
mrby1235-May-10 18:59 
AnswerRe: how to call srand(time(NULL)); Pin
Xing Chen5-May-10 20:12
Xing Chen5-May-10 20:12 
AnswerRe: how to call srand(time(NULL)); [modified] Pin
Peter_in_27805-May-10 20:26
professionalPeter_in_27805-May-10 20:26 
QuestionRe: how to call srand(time(NULL)); Pin
David Crow6-May-10 3:03
David Crow6-May-10 3:03 
GeneralRe: how to call srand(time(NULL)); Pin
mrby1236-May-10 5:42
mrby1236-May-10 5:42 
QuestionHow to convert 8# to 16# ? Pin
wangningyu5-May-10 17:41
wangningyu5-May-10 17:41 
AnswerRe: How to convert 8# to 16# ? Pin
Richard MacCutchan5-May-10 21:38
mveRichard MacCutchan5-May-10 21:38 
QuestionRe: How to convert 8# to 16# ? Pin
David Crow6-May-10 3:08
David Crow6-May-10 3:08 
Questionhow to store a RGB bitmap image in to an 2d byte array and how to display that image from array Pin
sravu255-May-10 16:23
sravu255-May-10 16:23 
AnswerRe: how to store a RGB bitmap image in to an 2d byte array and how to display that image from array Pin
enhzflep5-May-10 17:21
enhzflep5-May-10 17:21 
QuestionRicheditctrl displayed with Selection on Pin
ForNow5-May-10 15:07
ForNow5-May-10 15:07 
AnswerRe: Richeditctrl displayed with Selection on Pin
stebich6-May-10 2:12
professionalstebich6-May-10 2:12 
GeneralRe: Richeditctrl displayed with Selection on Pin
ForNow6-May-10 6:39
ForNow6-May-10 6:39 
Questionbool & BOOL Pin
dipuks5-May-10 12:21
dipuks5-May-10 12:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.