Location:
Search - ciocp
Search list
Description: 一个线程驰的类, 下面的是基本的使用方法 struct TSession { SOCKET socket int id } class myIocp:public CIOCP { public: void OnRead(void * p, char * buf, int len) void OnAccept(SOCKET socket) void OnClose(void * p) } void myIocp::OnAccept(SOCKET socket) { TSession *s = new TSession s->socket = socket //这里可以对连接的session进行自己的操作,例如给id找一个唯一的值 SetIoCompletionPort(socket, s) // 使连接socket与一个自定义结构体关联 } void myIocp::OnRead(void * p, char * buf, int len) { TSession *s = (TSession *)p send(s->socket, buf, len, 0) // 这里只是简单的把收到的消息返回给客户端 ... } void myIocp::OnClose(void * p) { delete p } myIoncp iocp main() { ... iocp.listen(4311) // 开始监听网络端口,等待客户端连接 ... }-A class for thread pool,basic usage below:
struct TSession { SOCKET socket int id } class myIocp:public CIOCP
{ public:
void OnRead(void * p, char * buf, int len)
void OnAccept(SOCKET socket)
void OnClose(void * p) }
void myIocp::OnAccept(SOCKET socket)
{ TSession *s = new TSession s->socket = socket
//here you can do something about connection session,such as find a unique id.
SetIoCompletionPort(socket, s)
// make connection socket associate with a custom structure }
void myIocp::OnRead(void * p, char * buf, int len)
{ TSession *s = (TSession *)p send(s->socket, buf, len, 0)
// return received message to client
void myIocp::OnClose(void * p) { delete p } myIoncp iocp main() { ... iocp.listen(4311)
//start listenning net port,wait for client connect.
Platform: |
Size: 2701 |
Author: boxu |
Hits:
Description: 一个线程驰的类, 下面的是基本的使用方法 struct TSession { SOCKET socket int id } class myIocp:public CIOCP { public: void OnRead(void * p, char * buf, int len) void OnAccept(SOCKET socket) void OnClose(void * p) } void myIocp::OnAccept(SOCKET socket) { TSession *s = new TSession s->socket = socket //这里可以对连接的session进行自己的操作,例如给id找一个唯一的值 SetIoCompletionPort(socket, s) // 使连接socket与一个自定义结构体关联 } void myIocp::OnRead(void * p, char * buf, int len) { TSession *s = (TSession *)p send(s->socket, buf, len, 0) // 这里只是简单的把收到的消息返回给客户端 ... } void myIocp::OnClose(void * p) { delete p } myIoncp iocp main() { ... iocp.listen(4311) // 开始监听网络端口,等待客户端连接 ... }-A class for thread pool,basic usage below:
struct TSession { SOCKET socket int id } class myIocp:public CIOCP
{ public:
void OnRead(void* p, char* buf, int len)
void OnAccept(SOCKET socket)
void OnClose(void* p) }
void myIocp::OnAccept(SOCKET socket)
{ TSession*s = new TSession s->socket = socket
//here you can do something about connection session,such as find a unique id.
SetIoCompletionPort(socket, s)
// make connection socket associate with a custom structure }
void myIocp::OnRead(void* p, char* buf, int len)
{ TSession*s = (TSession*)p send(s->socket, buf, len, 0)
// return received message to client
void myIocp::OnClose(void* p) { delete p } myIoncp iocp main() { ... iocp.listen(4311)
//start listenning net port,wait for client connect.
Platform: |
Size: 2048 |
Author: boxu |
Hits:
Description: 网络版游戏框架:1.服务器端,网络IO模型使用完成端口,具体实现是使用自行封装的CIOCP类,此类对完成端口的线程和对各种网络事件的处理进行了封装。封包的封装使用CPacket对封包进行打包和解包。2.客户端,使用异步选择事件模型,Socket使用自己封装的CMySocket进行方便的异步绑定。-Online Game Framework: 1. Server-side, the network model for the use of IO completion ports, concrete realization of the use of self-encapsulated CIOCP class, such pairs of completion port threads and the handling of a variety of network events were packaged. Packet encapsulation of the packets used to package CPacket reconciliation package. 2. The client, using an asynchronous event model selection, Socket to use their own package, CMySocket to facilitate asynchronous binding.
Platform: |
Size: 6552576 |
Author: zixue |
Hits: