Click to See Complete Forum and Search --> : Winsock MFC help


voidtech
May 15th, 1999, 09:35 AM
Hi, I am trying to open a connection on a port with a service on a unix box. The code I am pasting below is what I have so far. When OnSendPage() is executed a socket is created and I receive the response back from the server. I am successfully receiving the response and parsing the string but when I try to Send() when OnSend() is called I believe the string isn't being sent. If anyone can help with this I would appreciate it. I am brand new to sockets programming also. ;)



class CPagerSocket : public CAsyncSocket
{
public:
CPagerSocket(CPagerDlg *pDlg) {m_pDlg = pDlg;};
virtual void OnReceive(int nErrorCode);
virtual void OnSend( int nErrorCode);
virtual void OnClose(int nErrorCode);
CPagerDlg *m_pDlg;

};

void CPagerSocket::OnReceive(int nErrorCode)
{
char buf1[512];

Receive(&response, 512);
strncpy(buf1, response, 3);

if(strcmp(buf1, connected)==0)
{
m_pDlg->m_sResponse = buf1;
m_pDlg->UpdateData(FALSE);

AfxMessageBox("220 response received!");
}
else if(strcmp(buf1, user_accepted)==0)
{
m_pDlg->m_sResponse = buf1;
m_pDlg->UpdateData(FALSE);

AfxMessageBox("250 response received!");
}
else
{
AfxMessageBox("Bad response!");
}

OnSend(0);

}

void CPagerSocket::OnSend(int nErrorCode)
{
char buf2[512];


GetWindowText(m_pDlg->m_cText2Send, buf2, 512);
m_pDlg->m_sResponse=buf2;
m_pDlg->UpdateData(FALSE);
AfxMessageBox(buf2);

Send(buf2, strlen(buf2), 0);

OnReceive(0);

}

void CPagerSocket::OnClose(int nErrorCode)
{
m_pDlg->m_cSendPage.EnableWindow(TRUE);
delete this;
}

void CPagerDlg::OnSendPage()
{
CPagerSocket *pSocket;
pSocket = new CPagerSocket(this);
UpdateData(TRUE);
m_cSendPage.EnableWindow(FALSE);
pSocket->Create();
pSocket->AsyncSelect(FD_READ | FD_CLOSE);
pSocket->Connect(m_sHost, 444);


}


-----------------
Bruce Campbell
dhiarmid@cgc.ns.ca