Socket.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:2k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /********************************************************************
  2. created: 2003/02/14
  3. file base: Socket
  4. file ext: h
  5. author: liupeng
  6. purpose:
  7. *********************************************************************/
  8. #ifndef __INCLUDE_SOCKET_H__
  9. #define __INCLUDE_SOCKET_H__
  10. #if defined (_MSC_VER) && (_MSC_VER >= 1020)
  11. #pragma once
  12. #endif
  13. #ifndef _WINDOWS_
  14. #define WIN32_LEAN_AND_MEAN
  15. #include <windows.h>
  16. #undef WIN32_LEAN_AND_MEAN
  17. #endif
  18. #include <winsock2.h>
  19. #include "Win32Exception.h"
  20. #include "tstring.h"
  21. /*
  22.  * namespace OnlineGameLib::Win32
  23.  */
  24. namespace OnlineGameLib {
  25. namespace Win32 {
  26. /*
  27.  * CSocket
  28.  */
  29. class CSocket  
  30. {
  31. public:
  32. class InternetAddress;
  33. class Exception;
  34. CSocket();
  35. explicit CSocket( SOCKET theSocket );
  36. ~CSocket();
  37. void Attach( SOCKET theSocket );
  38. SOCKET Detatch();
  39. void Close();
  40. void AbortiveClose();
  41. void Shutdown( int how );
  42. void Listen( int backlog );
  43. void Bind( const SOCKADDR_IN &address );
  44. void Bind( const struct sockaddr &address, size_t addressLength );
  45. void Connect( const SOCKADDR_IN &address );
  46. void Connect( const struct sockaddr &address, size_t addressLength );
  47. private:
  48. SOCKET m_socket;
  49. /*
  50.  * No copies do not implement
  51.  */
  52. CSocket( const CSocket &rhs );
  53. CSocket &operator=( const CSocket &rhs );
  54. };
  55. /*
  56.  * CSocket::InternetAddress
  57.  */
  58. class CSocket::InternetAddress : public SOCKADDR_IN
  59. {
  60. public:
  61.       
  62. InternetAddress( unsigned long address, unsigned short port );
  63. InternetAddress( const _tstring &addressToConnectServer,
  64. unsigned short port );
  65. };
  66. /*
  67.  * CSocket::Exception
  68.  */
  69. class CSocket::Exception : public CWin32Exception
  70. {
  71. friend class CSocket;
  72. private:
  73. Exception( const _tstring &where, DWORD error );
  74. };
  75. } // End of namespace OnlineGameLib
  76. } // End of namespace Win32
  77. #endif //__INCLUDE_SOCKET_H__