class design question

A

Angus

Hello

I have some networking classes. I have a base class - CBasicSocket,
then a server socket which is CServerSocket : public CBasicSocket and
a client socket which is CClientSocket : public CBasicSocket.

The client class gets notified via a virtual function when the socket
is dosconnected. The server class gets notified if the server socket
is disconnected - ie the server shuts down.

My server class holds a collection of clients. When the server class
gets a connection from a new client, this collection gets
incremented. But I need to decrement the collection when a client
disconnects. But my CServerSocket class doesn't get notified about
this event. CClientSocket does. So does my CServerSocket class need
to contain a CClientSocket class? How do I set this up so that my
CServerSocket class gets the notification that a client has
disconnected?
 
J

Jim Langston

Angus said:
Hello

I have some networking classes. I have a base class - CBasicSocket,
then a server socket which is CServerSocket : public CBasicSocket and
a client socket which is CClientSocket : public CBasicSocket.

The client class gets notified via a virtual function when the socket
is dosconnected. The server class gets notified if the server socket
is disconnected - ie the server shuts down.

My server class holds a collection of clients. When the server class
gets a connection from a new client, this collection gets
incremented. But I need to decrement the collection when a client
disconnects. But my CServerSocket class doesn't get notified about
this event. CClientSocket does. So does my CServerSocket class need
to contain a CClientSocket class? How do I set this up so that my
CServerSocket class gets the notification that a client has
disconnected?

Are you using both CServerSocket and CClientSocket in the same program at
the same time? Can an instance of your program be both a Client and a
Server?

Your server class should know when a client disconnects, that's a part of
socket programming. Even if it's time out errors. If you have a
CServerSocket connected to a CClientSocket, that CClientSocket would be on a
different machine, wouldn't it?

Now, unless your CBasicSocket gets the disconnect notice and the
CServerSocket doesn't check or get informed, then have your CBasicSocket let
the CServerSocket know. It depends on your design.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top