Creating winsock client through MFC doc/view architecture

174 Views Asked by At

I have a game TicTacToe which was created in MFC with document/view architecture and I have server (standart console application) witn winsockets. Where I should initialize socket in client to connect it with server? (It must be exactly winsock, without Csocket). I know how to create winsockets, but I don't know WHERE I must create them in doc/view architecture. (The only I know is to initialize "WSADATA wsaData" in "InitInstance")

1

There are 1 best solutions below

0
On

It depends on your program design. If you utilised the whole Document/View architecture you would had document's File->Open / File->New / File->Save handlers. So, it seems right to put the communication code there.

However, if the Document is just a "dummy" class that was created by the Wizard, but never used, with all the code put in the View, then you can continue to enhance the program the same way. Put the "connection" part in your OnInitialUpdate method, and the disconnection part into WM_CLOSE handler.

It is probably a good idea to provide the user with "Connect" option (either via a Menu or Toolbar option, or both). Then put the code there