Jump to content
  • Advertisement
Sign in to follow this  

How to design a socket class

This topic is 2948 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

Hello, I am currently writing a wrapper class above boost::asio sockets.
So far I've written functions like connect, host, read, send and a few special ones.

My first question is: Is it better to make one class that can both host and connect.I mean you can write a client class and a server class too, but thats not proper?

and the other one: How should I design my class that user can change how to customize the way my socket handles data.
mysocket->read(); just puts the data into buffer, and then ? I need some kind of callback mechanism because read functions is called automatically I just want to know when there is a new data.


Share this post

Link to post
Share on other sites

You might want to add some Error function and possibly a Logging Function to be accessible for a user interface. String output than can be put in a progress output can greatly assist a user who has to supply connection data (IP/Ports).

Another advanced function is a connection test that blasts data between connector and host and generates sampled statistics like delay (useful in game programming...)

You didnt list Disconnect, it is often important that the other side know that you intentionally disconnected versus a lost connection. An application might want to know that info.

A higher level function might be a file transfer to pull or push a given file from the other side and put it onto the disk.
This might be a seperate Class and be done to demonstrate use of the lower level functions.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!