Archived

This topic is now archived and is closed to further replies.

My network API

This topic is 5618 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites