Sign in to follow this  

How to design a socket class

This topic is 2663 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.

Thanks

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

This topic is 2663 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this