Posted on 2003-03-07
Medium Priority
Last Modified: 2013-11-20
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;
Question by:xnisayx
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8089017
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.

Author Comment

ID: 8090173
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.
LVL 12

Expert Comment

ID: 8116034

  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.





Accepted Solution

modulo earned 0 total points
ID: 11812418
PAQed - no points refunded (of 50)

Community Support Moderator

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question