Link to home
Start Free TrialLog in
Avatar of xnisayx
xnisayx

asked on

Socket

Hi,
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;
Avatar of BigBadBob
BigBadBob

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.
Avatar of xnisayx

ASKER

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.
 


 

 

 

 
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial