Re: Simple email pop3/smtp source - I get a bind error



"Volodymyr M. Shcherbyna" <v_scherbina@xxxxxxxxxxxxxxx> wrote:

You still need to connect to server to trigger a "LIST" command. Take a look
at these implementations, it might help you:

http://www.codeproject.com/KB/IP/win32_pop3.aspx
http://www.codeproject.com/KB/IP/cpop3conn.aspx

Good luck,

Here's the full working code cut down for brevity. I've edited it from your
example. It works well with other connections except when trying to get replies
from my mail server. I have "mail.whatever.fi" but it's not a real address.

I am fairly new to socket programming btw.

when I took out "if (bind(..) { .. }" part I get error too.

DWORD WINAPI Thread1 (PVOID pvoid)
{
SOCKET listens;
SOCKET accepts;
struct sockaddr_in service={0};
struct hostent *h;

listens = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (listens == INVALID_SOCKET)
return 0;
service.sin_family=AF_INET;
h=gethostbyname("mail.whatever.fi");
service.sin_addr.s_addr=inet_addr(inet_ntoa(*((struct in_addr *)h->h_addr)));
service.sin_port=htons(110);
if (bind(listens, (SOCKADDR*)&service, sizeof(service)) == SOCKET_ERROR)
{ //this error comes up, bind fails
errorexit:
closesocket(listens);
ExitThread(0) ;
return 0; //not really necessary since ExitThread does it.
}
if (listen(listens, 1 ) == SOCKET_ERROR)
goto errorexit;
while (1)
{
accepts = accept(listens, NULL, NULL);
if (accepts==INVALID_SOCKET)
{
closesocket(accepts);
goto errorexit;
}
else
{ //all good exit anyway since this is just a test for connections
closesocket(accepts);
goto errorexit;
}
}
return 0;
}
.