MySocket.cpp
上传用户:chenhai826
上传日期:2007-04-11
资源大小:72k
文件大小:1k
源码类别:

破解

开发平台:

Visual C++

  1. // MySocket.cpp: implementation of the CMySocket class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "NoPassword.h"
  6. #include "MySocket.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CMySocket::CMySocket()
  16. {
  17. }
  18. CMySocket::~CMySocket()
  19. {
  20. }
  21. bool CMySocket::Create(void)
  22. {
  23. return (m_sock = socket(AF_INET,SOCK_STREAM,0)) != -1;
  24. }
  25. void CMySocket::Close(void)
  26. {
  27. closesocket(m_sock);
  28. }
  29. bool CMySocket::Connect(CString &host)
  30. {
  31. hostent *he;
  32. sockaddr_in addr;
  33. if((he = gethostbyname(host)) == NULL)
  34. return false;
  35. memset(&addr,0,sizeof(addr));
  36. addr.sin_family = AF_INET;
  37. addr.sin_port = htons(110); //pop3 port
  38. addr.sin_addr = *((in_addr *)he->h_addr);
  39. return connect(m_sock,(sockaddr *)&addr,sizeof(sockaddr)) != -1;
  40. }
  41. int CMySocket::Send(const char *buf,int buflen)
  42. {
  43. return send(m_sock,buf,buflen,0);
  44. }
  45. int CMySocket::Receive(char *buf,int buflen)
  46. {
  47. return recv(m_sock,buf,buflen,0);
  48. }