Need help on socket progrmming
-
I have class
CMySock
derived fromCAsyncSocket
and that class has a member asCMySock *pSock;
CMySock's object is created and kept in listen mode.When a connection reqest comes and CMySock's OnAccept() is called. There I want to connect to another system with pSock. and my code for that isif(!(m_pSrcClientSocket->m_pDestClientSocket)->Create()) { MessageBox("Falied to create a socket"); } else { if(!(m_pSrcClientSocket->m_pDestClientSocket)->Connect(rs.GetAt(0),port)) {// Here its failing to connect and gives an error WSAEWOULDBLOCK int err = GetLastError(); MessageBox("Failed to connect to Connect"); } else { // do something. } }
if the pointer is of CSocket instead of CMySock its connecting well. I want to user CMySock only. How to overcome this problem. Please help. Thank youKIRAN PINJARLA
-
I have class
CMySock
derived fromCAsyncSocket
and that class has a member asCMySock *pSock;
CMySock's object is created and kept in listen mode.When a connection reqest comes and CMySock's OnAccept() is called. There I want to connect to another system with pSock. and my code for that isif(!(m_pSrcClientSocket->m_pDestClientSocket)->Create()) { MessageBox("Falied to create a socket"); } else { if(!(m_pSrcClientSocket->m_pDestClientSocket)->Connect(rs.GetAt(0),port)) {// Here its failing to connect and gives an error WSAEWOULDBLOCK int err = GetLastError(); MessageBox("Failed to connect to Connect"); } else { // do something. } }
if the pointer is of CSocket instead of CMySock its connecting well. I want to user CMySock only. How to overcome this problem. Please help. Thank youKIRAN PINJARLA
Hi, why would you connect to another system at function OnAccept()? CMySock::OnAccept() { CMyClientSock *NewClientSock = new CMyClientSock(); Accept( NewClientSock, NULL, NULL ); //--> now the NewClientSock object is connected to the new incoming connection, you don't need construct / connect any object. } HTH Frank