cpp player

c++,设计模式,ACE,网络开发,架构设计,MMORPG
随笔 - 3, 文章 - 3, 评论 - 5, 引用 - 0
数据加载中……

TCP网络通讯常用接口,后续将提供DLL和LIB供测试

 

 1// 下列 ifdef 块是创建使从 DLL 导出更简单的
 2//宏的标准方法。此 DLL 中的所有文件都是用命令行上定义的 NET_EXPORTS
 3// 符号编译的。在使用此 DLL 的
 4//任何其他项目上不应定义此符号。这样,源文件中包含此文件的任何其他项目都会将 
 5// NET_API 函数视为是从此 DLL 导入的,而此 DLL 则将用此宏定义的
 6// 符号视为是被导出的。
 7#ifdef NET_EXPORTS
 8#define NET_API __declspec(dllexport)
 9#else
10#define NET_API __declspec(dllimport)
11#endif
12
13#define WIN32_LEAN_AND_MEAN    
14#include <windows.h>
15
16#ifndef SOCKET
17typedef unsigned int    SOCKET;
18#endif
19
20#pragma once
21
22/************************************************************************/
23/*       应用自实现消息协议接口                                         */
24/************************************************************************/
25class NET_API ISocketEvent
26{
27public:
28    virtual int     OnRcvMsg(SOCKET hSock , const char* buf, int nLen)    = 0;
29}
;
30/************************************************************************/
31/*      通讯服务端接口                                                    */
32/************************************************************************/
33class NET_API INetServer
34{
35public:
36    INetServer( ISocketEvent &event ):m_event(event)    
37    {}
38    virtual ~INetServer()    
39    {}
40
41    virtual bool Start( unsigned short usPort , unsigned int unRecvSize = 4*1024 ) = 0 ;
42    virtual bool Stop() = 0 ;
43    virtual void Release() = 0 ;
44    virtual void SendMsg( SOCKET hSock , const char *Buf, int nLen ) = 0;
45    virtual void BroadcastMsg( const char *buf , int len ) = 0 ;
46
47protected:
48    ISocketEvent &m_event;
49}
;
50/************************************************************************/
51/*      通讯客户端接口                                                    */
52/************************************************************************/
53class NET_API INetClient
54{
55public:
56    INetClient( ISocketEvent &event ):m_event(event)
57    {}
58    virtual ~INetClient()
59    {}
60
61    virtual bool Start( const char *pszIp , unsigned short usPort , unsigned int nMaxConnections ) = 0 ;
62    virtual bool Stop() = 0 ;
63    virtual void Release() = 0 ;
64    virtual void SendMsg( SOCKET hSock , const char *Buf, int nLen ) = 0;
65    virtual void BroadcastMsg( const char *buf , int len ) = 0 ;
66protected:
67    ISocketEvent &m_event;
68}
;
69
70extern "C"
71{
72    NET_API INetServer * CreateServer(  ISocketEvent &event );
73    NET_API INetClient * CreateClient(  ISocketEvent &event );
74}
;

posted on 2010-05-26 23:35 appstudy 阅读(227) 评论(0)  编辑 收藏 引用 所属分类: Network


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理