Hi everyone,
I'm currently working a Network class. For the moment, I have a class containing the following functions :
I think it should be a good thing to separate the server functions of the generic ones ("send_to"/"receive_from") and I should add a "connect_to" one.
When I have a server, if I accept a connection, a new socket number is created, so I need to have 2 socket variable in the class. It's not needed when I have to use a client connection. So, I would like to build the following inheritance of class:
parent : cNetwork (containing the socket and receive_from / send_to functions)
childrens :
cNetwork_server (containing the bind, accept...)
cNetwork_client (containing the connect and other usefull functions to search the dns etc...)
This mean the cNetwork_server class need to access to the socket variable of the parent class. Is this a good practice to use ?
Can you see another way to do this ? Any advice ???
Here the code of the class to be sure everybody can understand what I would like to do:
thank you for your precious help!
I'm currently working a Network class. For the moment, I have a class containing the following functions :
Code:
class cNetwork
{
cnetwork();
cnetwork(int port);
~cnetwork();
void send_to(char *buffer,int length);
int receive_from(char *buf,int buf_size);
void bind_to(void);
void wait_connection(void);
};
I think it should be a good thing to separate the server functions of the generic ones ("send_to"/"receive_from") and I should add a "connect_to" one.
When I have a server, if I accept a connection, a new socket number is created, so I need to have 2 socket variable in the class. It's not needed when I have to use a client connection. So, I would like to build the following inheritance of class:
parent : cNetwork (containing the socket and receive_from / send_to functions)
childrens :
cNetwork_server (containing the bind, accept...)
cNetwork_client (containing the connect and other usefull functions to search the dns etc...)
This mean the cNetwork_server class need to access to the socket variable of the parent class. Is this a good practice to use ?
Can you see another way to do this ? Any advice ???
Here the code of the class to be sure everybody can understand what I would like to do:
Code:
class cNetwork
{
public:
cNetwork();
~cNetwork();
void send_to(char *buffer,int size);
int receive_from(char *buffer,int size);
protected:
int socket;
};
class cNetwork_server : cNetwork
{
/* I must use the variable socket of the parent class withing the functions of this class */
cNetwork_server();
~cNetwork_server();
void bind_to();
void wait_for_connection();
};
class cNetwork_client : cNetwork
{
/* I must use the variable socket of the parent class withing the functions of this class */
cNetwork_client();
~cNetwork_client();
void connect_to();
};
thank you for your precious help!