Presentation is loading. Please wait.

Presentation is loading. Please wait.

Khongorzul D Window Programming CBNU,

Similar presentations


Presentation on theme: "Khongorzul D Window Programming CBNU,"— Presentation transcript:

1 Khongorzul D. 2006.11.28 Window Programming CBNU,
LAN Socket Khongorzul D. Window Programming CBNU,

2 - How applications use the Winsock interface to perform network communications between two or more computers. - The difference between a client and a server application and the role each plays in establishing a communications link. - How the MFC Winsock classes simplify the process of writing Internet applications. - How can create own Winsock class, descended from the MFC Winsock classes, to easily build an event-driven, networking application.

3 Outline How Do Network Communication Work?
Building a Network Application Creating the Application Shell Window Layout and Startup Functionality Inheriting from the CAsyncSocket Class Connecting the Application Sending and Receiving Ending the Connection Summary

4 How Do Network Communication Work?
One application sits on a computer, waiting for another application to open a communication connection This application is “listening” for this connection request. “ like you listen for the phone to ring” Tries to open connection Accepts connection request Messages sent both directions Client Server (Listening for connections) Figure 1: The basic socket connection process

5 Creating the Application Shell
Create a new MFC AppWizard project Name : Sock first step of the AppWizard --> Dialog-based application. second step of the AppWizard  Windows Sockets

6 Creating the Application Shell
We can layout the main dialog for your application. set of radio buttons: client or server. need a couple of edit boxes: computer name and port need a command button: connection need an edit box: message send need a couple of list boxes: messages sent and received.

7 Creating the Application Shell
Setting all of the control properties as specified in following table Object Property Setting Group Box ID IDC_STATICTYPE 20 Caption Socket Type Radio Button IDC_RCLIENT &Client Group Checked IDC_RSERVER &Server Static Text ID IDC_STATICNAME Server &Name: Edit Box IDC_ESERVNAME IDC_STATICPORT Server &Port: IDC_ESERVPORT Command Button IDC_BCONNECT C&onnect

8 Creating the Application Shell
Setting all of the control properties as specified in following table Command Button ID IDC_BCONNECT Caption C&onnect IDC_BCLOSE C&lose Disabled Checked Static Text IDC_STATICMSG &Message: Edit Box IDC_EMSG IDC_BSEND S&end IDC_STATIC Sent: List Box IDC_LSENT Tab Stop Unchecked Sort Selection None Received

9 Creating the Application Shell
Open Class Wizard to attach variables to the controls on the dialog, by following table

10 Creating the Application Shell
Open Class Wizard to attach variables to the controls on the dialog, by following table

11 Creating the Application Shell
Add functionality to application Function : BN_CLICKED event message for the IDC_RCLIENT control ID, Function name: OnRType. Function: BN_CLICKED event message for the IDC_RSERVER control ID.

12 Inherent from the CAsyncSocket Class
Create own descendent class from CAsyncSocket. This class means of passing this event to the dialog that the object will be a member of. Select Insert  New Class  name for your class: CMySocket, select CAsyncSocket And created the socket class, add a member variable to the class to serve as a pointer to the parent dialog window. Variable type: CDialog*, variable name: m_pWnd access as: private. add a member function to your new socket class. Specify the function And add a member function to your new socket class. Type: void, Declaration: SetParent(CDialog* pWnd), Access: public.


Download ppt "Khongorzul D Window Programming CBNU,"

Similar presentations


Ads by Google