• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:


I'd like to write a simple program like chat but I can't add CSocket.
I'd like to handle OnAccpet(), OnReceive(), OnSend()
I'd like to choose "simpe document"

1-  File
2-  New (Poroject Name="CSP" type="MFC")
3-  Type of applicatin "Single document"
4-  Finish
Could you explain me the other steps, what I should do;
1 Solution
well using the MFC you can use the CAsyncSocket. If you derive a your own version of that class, for instance CMySocket then you can use that.

In CMySocket you have to override the public void methods OnAccept(int errorCode), OnConnect(int errorCode), OnClose(int errorCode), OnSend(int errorCode) and OnReceive(int errorCode).

In your apps code, you should also provide these methods. In your CMySocket class have each of the above methods test the errorCode int and if its 0, call the corresponding method in your app.

In your app create an instance of the CMySocketClass. You can then call Create() and Connect() (or Listen() if you are the server) and go from there.
xnisayxAuthor Commented:
I am a junior MFC programmer so it is difficult to do so for me. Can you explain step by step.

NOTE: I must use "Single document" application type.

  Recreate you project.
  On the Last Dialog of the Creation Wizard at th bottom Left choose 'CFormView'

  You will notice in the resource setion of your project you have a Dialog template.

  Drag a ListBox an edit control and a button on to this dialog. (Tools/Customize/Toolbars click resource for resource toolbar)
  Arrange the controls. Listbox on top, text will be displayed here
  Edit below, you enter text here
  Button to right of edit.
  Right click on button and give it the name send.

  Thats your GUI.

  Press Ctrl-w for Class Wizard
  Accept Defaults
  Press  Add Class at top right
  Choose New class
  Type in ChatClass (or whatever)
  The Base Class is CAsncySocket
  Accept defaults

  You can now select the functions for CAsync.




PAQed - no points refunded (of 50)

Community Support Moderator

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now