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


voidtech
May 11th, 1999, 09:22 AM
I am trying to open a socket with a server on a specified port. Right now all I want to do is create the socket and open the connection with the server. I am new to the sockets thing and could use some help. After creating a small dialog based application with winsock support I declare:

//declared public in the dialog class

CAsyncSocket m_thesocket;

//then I call its Create method on the action of a pushbutton

if(m_thesocket.Create())
{
AfxMessageBox("Socket successfully created!");
}
else
{
AfxMessageBox("Socket creation error!");
}

//now for the connection - using a unix pop server - is this ok?

if (m_thesocket.Connect("servename.com", 25))
{
AfxMessageBox("Connection successfull!");
}
else
{
AfxMessageBox("Connection error!");
}

Right now I just want to know that the connection is made. But for some reason it is not being made. Is it possible to open a connection with a pop server on port 25 in this manner? Any help would be greatly appreciated. Thanks in advance.

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

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

August 5th, 1999, 09:18 AM
After you call Connect you cannot test the result. Even though the documentation says that connect can return an error, it never does (or almost).

What you have to do is overwrite the OnConnect message of CAsyncSocket. You call the Connect as you already did but you place your messages in the OnConnect function.

Like this, it will work.
Good luck!

Karsten Döring
August 5th, 1999, 10:31 AM
Hi,

normaly u get an error message when u try to connect in the form of WSAEWOULDBLOCK.

You can do 2 things now:

1. Ignore it because your connection is ok.
2. Before calling Connect call:
DWORD n = 0;
m_thesocket.IOCtl( FIONBIO, n )

But as u already written, if you are new to sockets, it's a bit more difficult to find the right server for an email adress.

for example kd@dedenet.de ( my email adress ). If u try to connect to dedenet.de on port 25 it will fail, because there is no SMTP-Server. You have to look at the MX Entry for dedenet.de which points in that case to SMTP.DEDENET.DE

I don't know if u did this already and tries to connect to a valid smtp-server. In general the first thing I wrote ( WOULDBLOCK ) would solve your problem.

Hope it helps.

Karsten