MySocket.cpp
上传用户:chenhai826
上传日期:2007-04-11
资源大小:72k
文件大小:1k
- // MySocket.cpp: implementation of the CMySocket class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "NoPassword.h"
- #include "MySocket.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMySocket::CMySocket()
- {
- }
- CMySocket::~CMySocket()
- {
- }
- bool CMySocket::Create(void)
- {
- return (m_sock = socket(AF_INET,SOCK_STREAM,0)) != -1;
- }
- void CMySocket::Close(void)
- {
- closesocket(m_sock);
- }
- bool CMySocket::Connect(CString &host)
- {
- hostent *he;
- sockaddr_in addr;
- if((he = gethostbyname(host)) == NULL)
- return false;
- memset(&addr,0,sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(110); //pop3 port
- addr.sin_addr = *((in_addr *)he->h_addr);
- return connect(m_sock,(sockaddr *)&addr,sizeof(sockaddr)) != -1;
- }
- int CMySocket::Send(const char *buf,int buflen)
- {
- return send(m_sock,buf,buflen,0);
- }
- int CMySocket::Receive(char *buf,int buflen)
- {
- return recv(m_sock,buf,buflen,0);
- }