Advertisement

My network API

Started by July 25, 2002 03:45 AM
0 comments, last by Zorak 22 years, 6 months ago
After a few days of coding Im starting to see the end of it in the horizon. What I did is build a small c++ library. it looks like this: CInetBase - Opens Winsock and handles OS specific stuff CInetConnection - Base class for connections. | +CTCPConnection - Derived from CInetConnection | +CUDPConnection - Derived from CInetConnection | +CIPXConnection - Planned only CInetPacket - Virtual class for packets | +-CPktHello - Aknowledges connection +-CPktBye - Discconnects +-CPktText - Sends a packet containing text +-CPktData - Sends a packet containing data +-CPktRelay - Moves a connection (from TCP to UDP or to a different server, port) How it works is, you start up the baseclass to init everything. Then you open a connection, either with Connect (connects to remote host) or with Listen (listen for incoming traffic). Sending/recieving is quite easy, you just derive a class from CInetPacket and tell it how it should handle data. And off you go. Example:
  
int main ( int argc, char **argv ) {
 CInetBase _inetBase; 
 CTCPConnection _myConn("127.0.0.1",9090); 
 _myConn.SendPkt(new CPktText("This is a test string");

 return 0;
}
  
The CPktText class does this:
  
class CPktText : public CInetPacket
{
public:

   CPktText (char *a_szText) {
      this->m_nLength = strlen(Text);
      this->m_ptType = CInetPacket::Pkg_Text;
      strcpy(this->m_aData,a_szText);
   }

};
  
The connection classes also do either call callbacks when remote connections connect/disconnect or handle them by themselves. Right now im working on the CUDPClass, Im about to implement a sequencing system. Im still working on it so there is no point in talking about it, since Im not sure how it all will work yet :D Im considering to release the sourcecode and perhaps write a tutorial or something. Would this be of any intrest or is it to basic for you Guru people you?
Domine non secundum peccata nostra facias nobis
of course! a network api is always interesting. i hope you can write a tutorial about it. if possible please email me the source code (yoshi_x@hotmail.com). keep up the good work!

This topic is closed to new replies.

Advertisement