c++ - Is my design for UDP socket server correct? -


i designing server used in udp communication using mfc. have following classes

  • cmydlialog - take care of user interface
  • ccontroller - act mediator between classes
  • cprotocolmanager - take care of encoding/decoding msgs (this static class)
  • cconnectionmanager - take care of udp connection, sending, receiving

i creating object of cconnectionmanager member variable in ccontroller , object of ccontroller member variable in cmydialog.

when user type , presses send, calling method in ccontroler call method in cprotocolmanager construct packet , call cconnectionmanager method send it.

when receive data, handled in thread of cconnectionmanager. there creating local object of ccontroller , call method, pass data cprotocolmanager decode.

now want inform ui data, how should ccontroler it? can post message ui making main dialog handle global, correct approach.

also tell me whether design correct one.

thanks in advance

i think designs never right or wrong, can rate them according principles many people consider "good" (see the solid principles).

your sending approach sounds reasonable, making dialog global receiving considered "not good". see the hollywood principle. suggest better pass callback method connection manager method of ccontroller (which lets cprotocolmanager decode , calls callback method dialog). if callbacks not want can define abstractbaseclasses (abc) "abstractmessagereceiver" method

 virtual void receive(const char*, int length) = 0; 

you can implement abc in cprotocolmanager pass "abstractmessagereceiver*" cconnectionmanager calls

m_mymessagereceiver->receive(m_buffer, m_length); 

or similar.

this approach reduces coupling, more testable , increases reusability.

furthermore, agree should think threading model!


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -