The following MFC example program illustrates the functions of Windows Sockets:
CHATTER is a Windows Socket Client sample application. It is a single document interface (SDI) application with a split window that allows users to send messages to the discussion server (CHATSRVR ), the discussion server then sends the message to multiple other CHATTER users at the same time.
By sending the CHATTER application to the server a broadcast data packet instead of a message stream, you can write CHATTER and CHATSRVR without using the client/server model. However, unlike streaming sockets, the data message socket cannot be guaranteed to be transmitted. Therefore, some messages may not reach all other users in the discussion. Generate and run an example
Generate and run a CHATTER example
- Open solution chatter. sln.
- Click Generate on the generate menu ".
- Click Start execution (not debugging) on the Debug menu )".
When running CHATTER, you need to enter the following content in the "Setup" dialog box:
-
Handle
-
The name used to address all messages. For example, you can select ". The name" ".
-
Server
-
The IP address of the computer that runs the CHATSVR example.
-
Channel
-
Identifies the number of discussions to be added (one computer can run multiple discussion servers ).
After all the information is provided and click "OK", the main application window appears. To send a message, type a message in the lower pane. Press ENTER to send a message. To send multi-line messages, press CTRL + ENTER. Keywords
This example illustrates the following keywords:
AfxGetApp, AfxMessageBox, CArchive: Flush, CArchive: IsStoring, CControlBar: EnableDocking, CControlBar: GetBarStyle, CControlBar: SetBarStyle, CDialog: DoModal, CDocument :: parameters, CDocument: Alert, CDocument: GetNextView, CDocument: OnNewDocument, CEditView: GetEditCtrl, CEditView: SerializeRaw, CFrameWnd: DockControlBar, CFrameWnd: Alert, CFrameWnd :: onCreateClient, CFrameWnd: SetActiveView, CObject: AssertValid, CObject: Dump, CObject: IsKindOf, CObject: Serialize, CRect: Size, metadata: CreateView, role :: getPane, CStatusBar: Create, CStatusBar: SetIndicators, CString: GetBuffer, CString: GetLength, CString: IsEmpty, CString: LoadString, CString: ReleaseBuffer, CToolBar :: create, CToolBar: LoadBitmap, CToolBar: SetButtons, CView: GetDocument, CView: OnDraw, CWinApp: AddDocTemplate, CWinApp: InitInstance, CWinApp: example, CWinApp :: onFileNew, CWnd: DestroyWindow, CWnd: DoDataExchange, CWnd: GetClientRect, CWnd: GetWindowText, CWnd: Counter, CWnd: KillTimer, CWnd: OnChar, CWnd :: onCreate, CWnd: OnTimer, CWnd: PreCreateWindow, CWnd: SetTimer, CWnd: SetWindowText, SetWindowText, rand, wsprintf
Note:Some examples (such examples) have not been modified to reflect changes in the Visual C ++ wizard, library, and compiler, but still demonstrate how to complete the required tasks.
See
MFC example
CHATSRVR is a Windows Socket Server Sample application. It is a single-Document Interface (SDI) application that is used to discuss the server for the client implementation of the CHATTER sample.
By sending the CHATTER application to the server a broadcast data packet instead of a message stream, you can write CHATTER and CHATSRVR without using the client/server model. However, unlike streaming sockets, the data message socket cannot be guaranteed to be transmitted. Therefore, some messages may not reach all other users in the discussion. Generate and run an example
Generate and run the CHATSRVR example
- Open the chatsrvr. sln solution.
- Click Generate on the generate menu ".
- Click Start execution (not debugging) on the Debug menu )".
When running CHATSRVR, a "Discussion" dialog box for entering "Channel" is displayed. "Channel" indicates the number of discussions to be supported (one computer can run multiple discussion servers ). After you provide this information and click "OK", the main application window appears. Keywords
This example illustrates the following keywords:
Examples, CArchive: Flush, CArchive: IsStoring, CCmdUI: Enable, CCmdUI: SetText, CControlBar: enabled, CControlBar: GetBarStyle, CControlBar: SetBarStyle, cdibarstyle :: doModal, CDocument: DeleteContents, CDocument: OnNewDocument, CEditView: GetEditCtrl, CFrameWnd: DockControlBar, CFrameWnd: lower, CObject: lower, CObject: Dump, CObject :: serialize, CStatusBar: Create, CStatusBar: SetIndicators, CString: GetBuffer, CString: LoadString, CString: ReleaseBuffer, CToolBar: Create, CToolBar: LoadBitmap, CToolBar :: setButtons, CView: GetDocument, CView: OnDraw, CWinApp: AddDocTemplate, CWinApp: ExitInstance, CWinApp: InitInstance, CWinApp: Signature, CWinApp: OnFileNew, CWnd :: doDataExchange, CWnd: GetWindowTextLength, CWnd: OnCreate, SetWindowText, wsprintf
Note:Some examples (such examples) have not been modified to reflect changes in the Visual C ++ wizard, library, and compiler, but still demonstrate how to complete the required tasks.
See
MFC example