亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch20.htm

?? /// //Visual C++ 6.0 21天自學教程
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
25:         // Server, create a socket bound to the port specified26:         m_sListenSocket.Create(m_iPort);27:         // Listen for connection requests28:         m_sListenSocket.Listen();29:     }30: }</PRE><P>Next, to complete the connection, you'll add the socket event function to thedialog class for the OnAccept and OnConnect event functions. These are the functionsthat your socket class is calling. They don't require any parameters, and they don'tneed to return any result code. For the OnAccept function, which is called for thelistening socket when another application is trying to connect to it, you'll callthe socket object's Accept function, passing in the connection socket variable. Onceyou've accepted the connection, you can enable the prompt and edit box for enteringand sending messages to the other application.</P><P>To add this function to your application, add a member function to the dialogclass (CSockDlg). Specify the function type as void, the declaration as OnAccept,and the access as public. Edit the function, adding the code in Listing 20.7.</P><P><H4>LISTING 20.7. THE CSockDlg OnAccept FUNCTION.</H4><PRE> 1: void CSockDlg::OnAccept() 2: { 3:     // Accept the connection request 4:     m_sListenSocket.Accept(m_sConnectSocket); 5:     // Enable the text and message controls 6:     GetDlgItem(IDC_EMSG)-&gt;EnableWindow(TRUE); 7:     GetDlgItem(IDC_BSEND)-&gt;EnableWindow(TRUE); 8:     GetDlgItem(IDC_STATICMSG)-&gt;EnableWindow(TRUE); 9: }</PRE><P>For the client side, there's nothing to do once the connection has been completedexcept enable the controls for entering and sending messages. You'll also enablethe Close button so that the connection can be closed from the client side (but notthe server side). To add this functionality to your application, add another memberfunction to the dialog class (CSockDlg). Specify the function type as void, the functiondeclaration as OnConnect, and the access as public. Edit the function, adding thecode in Listing 20.8.</P><P><H4>LISTING 20.8. THE CSockDlg OnConnect FUNCTION.</H4><PRE> 1: void CSockDlg::OnConnect() 2: { 3:     // Enable the text and message controls 4:     GetDlgItem(IDC_EMSG)-&gt;EnableWindow(TRUE); 5:     GetDlgItem(IDC_BSEND)-&gt;EnableWindow(TRUE); 6:     GetDlgItem(IDC_STATICMSG)-&gt;EnableWindow(TRUE); 7:     GetDlgItem(IDC_BCLOSE)-&gt;EnableWindow(TRUE); 8: }</PRE><P>If you could compile and run your application now, you could start two copies,put one into listen mode, and then connect to it with the other. Unfortunately, youprobably can't even compile your application right now because your socket classis looking for several functions in your dialog class that you haven't added yet.Add three member functions to the dialog class (CSockDlg). Specify all of them asvoid functions with public access. Specify the first function's declaration as OnSend,the second as OnReceive, and the third as OnClose. You should now be able to compileyour application.</P><P>Once you've compiled your application, start two copies of the application, side-by-side.Specify that one of these two should be the server, and click the Listen button toput it into listen mode. Leave the other as the client and click the Connect button.You should see the connection controls disable and the message sending controls enableas the connection is made, as in Figure 20.6.</P><P><A HREF="javascript:popUp('20fig06.gif')"><B>FIGURE 20.6.</B></A><B> </B><I>Connectingthe two applications.</I></P><BLOCKQUOTE>	<P><HR><STRONG>TIP:</STRONG> Be sure that you have the server application listening before you	try to connect it to the client application. If you try to connect to it with the	client application before the server is listening for the connection, the connection	will be rejected. Your application will not detect that the connection was rejected	because you haven't added any error handling to detect this event.<BR>	<STRONG>TIP:</STRONG> To run these applications and get them to connect, you'll need TCP/IP	running on your computer. If you have a network card in your computer, you may already	have TCP/IP running. If you do not have a network card, and you use a modem to connect	to the Internet, then you will probably need to be connected to the Internet when	you run and test these applications. When you connect to the Internet through a modem,	your computer usually starts running TCP/IP once the connection to the Internet is	made. If you do not have a network card in your computer, and you do not have any	means of connecting to the Internet, or any other outside network that would allow	you to run networked applications, you may not be able to run and test today's applications	on your computer.<HR></BLOCKQUOTE><H3><A NAME="Heading13"></A>Sending and Receiving</H3><P>Now that you are able to connect the two running applications, you'll need toadd functionality to send and receive messages. Once the connection is establishedbetween the two applications, the user can enter text messages in the edit box inthe middle of the dialog window and then click the Send button to send the messageto the other application. Once the message is sent, it will be added to the listbox of sent messages. To provide this functionality, when the Send button is clicked,your application needs to check whether there is a message to be sent, get the lengthof the message, send the message, and then add the message to the list box. To addthis functionality to your application, use the Class Wizard to add a function tothe clicked event of the Send (IDC_BSEND) button. Edit this function, adding thecode in Listing 20.9.</P><P><H4>LISTING 20.9. The CSockDlg OnBsend FUNCTION.</H4><PRE> 1: void CSockDlg::OnBsend() 2: { 3:     // TODO: Add your control notification handler code here 4:     int iLen; 5:     int iSent; 6: 7:     // Sync the controls with the variables 8:     UpdateData(TRUE); 9:     // Is there a message to be sent?10:     if (m_strMessage != &quot;&quot;)11:     {12:         // Get the length of the message13:         iLen = m_strMessage.GetLength();14:         // Send the message15:         iSent = m_sConnectSocket.Send(LPCTSTR(m_strMessage), iLen);16:         // Were we able to send it?17:         if (iSent == SOCKET_ERROR)18:         {19:         }20:         else21:         {22:             // Add the message to the list box.23:             m_ctlSent.AddString(m_strMessage);24:             // Sync the variables with the controls25:             UpdateData(FALSE);26:         }27:     }28: }</PRE><P>When the OnReceive event function is triggered, indicating that a message hasarrived, you'll retrieve the message from the socket using the Receive function.Once you've retrieved the message, you'll convert it into a CString and add it tothe message-received list box. You can add this functionality by editing the OnReceivefunction of the dialog class, adding the code in Listing 20.10.</P><P><H4>LISTING 20.10. THE CSockDlg OnReceive FUNCTION.</H4><PRE> 1: void CSockDlg::OnReceive() 2: { 3:     char *pBuf = new char[1025]; 4:     int iBufSize = 1024; 5:     int iRcvd; 6:     CString strRecvd; 7: 8:     // Receive the message 9:     iRcvd = m_sConnectSocket.Receive(pBuf, iBufSize);10:     // Did we receive anything?11:     if (iRcvd == SOCKET_ERROR)12:     {13:     }14:     else15:     {16:         // Truncate the end of the message17:         pBuf[iRcvd] = NULL;18:         // Copy the message to a CString19:         strRecvd = pBuf;20:         // Add the message to the received list box21:         m_ctlRecvd.AddString(strRecvd);22:         // Sync the variables with the controls23:         UpdateData(FALSE);24:     }25: }</PRE><P>At this point, you should be able to compile and run two copies of your application,connecting them as you did earlier. Once you've got the connection established, youcan enter a message in one application and send it to the other application, as shownin Figure 20.7.</P><P><A HREF="javascript:popUp('20fig07.gif')"><B>FIGURE 20.7.</B></A><B> </B><I>Sendingmessages between the applications.</I></P><P><I></I><H3><A NAME="Heading14"></A>Ending the Connection</H3><P>To close the connection between these two applications, the client applicationuser can click the Close button to end the connection. The server application willthen receive the OnClose socket event. The same thing needs to happen in both cases.The connected socket needs to be closed, and the message sending controls need tobe disabled. On the client, the connection controls can be enabled because the clientcould change some of this information and open a connection to another server application.Meanwhile, the server application continues to listen on the port that it was configuredto listen to. To add all this functionality to your application, edit the OnClosefunction, adding the code in Listing 20.11.</P><P><H4>LISTING 20.11. THE CSockDlg OnClose FUNCTION.</H4><PRE> 1: void CSockDlg::OnClose() 2: { 3:     // Close the connected socket 4:     m_sConnectSocket.Close(); 5:     // Disable the message sending controls 6:     GetDlgItem(IDC_EMSG)-&gt;EnableWindow(FALSE); 7:     GetDlgItem(IDC_BSEND)-&gt;EnableWindow(FALSE); 8:     GetDlgItem(IDC_STATICMSG)-&gt;EnableWindow(FALSE); 9:     GetDlgItem(IDC_BCLOSE)-&gt;EnableWindow(FALSE);10:     // Are we running in Client mode?11:     if (m_iType == 0)12:     {13:         // Yes, so enable the connection configuration controls14:         GetDlgItem(IDC_BCONNECT)-&gt;EnableWindow(TRUE);15:         GetDlgItem(IDC_ESERVNAME)-&gt;EnableWindow(TRUE);16:         GetDlgItem(IDC_ESERVPORT)-&gt;EnableWindow(TRUE);17:         GetDlgItem(IDC_STATICNAME)-&gt;EnableWindow(TRUE);18:         GetDlgItem(IDC_STATICPORT)-&gt;EnableWindow(TRUE);19:         GetDlgItem(IDC_RCLIENT)-&gt;EnableWindow(TRUE);20:         GetDlgItem(IDC_RSERVER)-&gt;EnableWindow(TRUE);21:         GetDlgItem(IDC_STATICTYPE)-&gt;EnableWindow(TRUE);22:     }23: }</PRE><P>Finally, for the Close button, call the OnClose function. To add this functionalityto your application, use the Class Wizard to add a function to the clicked eventfor the Close button (IDC_BCLOSE). Edit the function to call the OnClose function,as in Listing 20.12.</P><P><H4>LISTING 20.12. THE CSockDlg OnBclose FUNCTION.</H4><PRE> 1: void CSockDlg::OnBclose() 2: { 3:     // TODO: Add your control notification handler code here 4:     // Call the OnClose function 5:     OnClose(); 6: }</PRE><P>If you compile and run your application, you can connect the client applicationto the server, send some messages back and forth, and then disconnect the clientby clicking the Close button. You'll see the message-sending controls disable themselvesin both applications, as in Figure 20.8. You can reconnect the client to the serverby clicking the Connect button again and then pass some more messages between thetwo, as if they had never been connected in the first place. If you start a thirdcopy of the application, change its port number, designate it as a server, and putit into listening mode, you can take your client back and forth between the two servers,connecting to one, closing the connection, changing the port number, and then connectingto the other.</P><P><A HREF="javascript:popUp('20fig08.gif')"><B>FIGURE 20.8.</B></A> <I>Closing theconnection between the applications.</I></P><P><I></I><H2><A NAME="Heading15"></A>Summary</H2><P>Today, you learned how you can enable your applications to communicate with othersacross a network or across the Internet by using the MFC Winsock classes. You tooka good look at the CAsyncSocket class and learned how you could create your own descendentclass from it that would provide your applications with event-driven network communications.You learned how to create a server application that can listen for and accept connectionsfrom other applications. You also learned how to build a client application thatcan connect to a server. You learned how to send and receive messages over a socketconnection between two applications. Finally, you learned how to close the connectionand how to detect that the connection has been closed.</P><P><H2><A NAME="Heading16"></A>Q&amp;A</H2><DL>	<DT></DT>	<DD><B>Q How do Internet applications work?</B>	<P>	<DT><B></B></DT>	<DD><B>A</B> Most Internet applications use the same functionality that you created	today. The primary difference is that the applications have a script of messages	that are passed back and forth. The messages consist of a command and the data that	needs to accompany that command. The server reads the command and processes the data	appropriately, sending back a status code to let the client know the success or failure	of the command. If you want to learn more about how Internet applications do this,	several books cover this subject area in detail.	<P>	<DT></DT>	<DD><B>Q How does a server application handle a large number of simultaneous connections	from clients?</B>	<P>	<DT><B></B></DT>	<DD><B>A</B> With a full-strength server, the connection sockets are not declared	as class variables. The server instead uses some sort of dynamic allocation of sockets,	in an array or link-list, to create sockets for the clients as the connection requests	come in. Another approach often taken by servers is to spin off a separate thread	for each connection request. This allows the application to have a single socket	connection per thread, and keeping track of the sockets is much easier. In any case,	server applications don't normally have a single connection socket variable.	<P></DL><H2><A NAME="Heading17"></A>Workshop</H2><P>The Workshop provides quiz questions to help you solidify your understanding ofthe material covered and exercises to provide you with experience in using what you'velearned. The answers to the quiz questions and exercises are provided in AppendixB, &quot;Answers.&quot;</P><P><H3><A NAME="Heading18"></A>Quiz</H3><DL>	<DT></DT>	<DD><B>1. </B>What are the two things that a client application must know to be able	to connect to a server application?	<P>	<DT></DT>	<DD><B>2. </B>What CAsyncSocket function is used to enable a server application to	detect connection efforts by client applications?	<P>	<DT></DT>	<DD><B>3. </B>What CAsyncSocket member function is called to signal that data has	arrived through a socket connection?	<P>	<DT></DT>	<DD><B>4. </B>What function is called to signal that a connection has been established?	<P>	<DT></DT>	<DD><B>5. </B>What function do you use to send a message through a socket connection	to the application on the other end?	<P></DL><H3><A NAME="Heading19"></A>Exercise</H3><P>The server application that you wrote can handle only a single connection at atime. If a second application tries to open a connection to it while it's got anexisting connection to an application, the server application will crash. The servertries to accept the second connection into the socket that is already connected tothe first client application. Add a third socket object to the application that willbe used to reject additional client connections until the first client closes theconnection.</P><H1></H1><CENTER><P><HR><A HREF="../ch19/ch19.htm"><IMG SRC="../button/previous.gif" WIDTH="128" HEIGHT="28"ALIGN="BOTTOM" ALT="Previous chapter" BORDER="0"></A><A HREF="../ch21/ch21.htm"><IMGSRC="../button/next.gif" WIDTH="128" HEIGHT="28" ALIGN="BOTTOM" ALT="Next chapter"BORDER="0"></A><A HREF="../index.htm"><IMG SRC="../button/contents.gif" WIDTH="128"HEIGHT="28" ALIGN="BOTTOM" ALT="Contents" BORDER="0"></A> <BR><BR></P><P>&copy; <A HREF="../copy.htm">Copyright</A>, Macmillan Computer Publishing. Allrights reserved.</CENTER></BODY></HTML>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品自拍偷拍| 五月天婷婷综合| 午夜在线成人av| 国产成人精品免费在线| 在线成人午夜影院| 亚洲另类在线视频| 国产一区二区91| 日韩欧美一卡二卡| 亚洲图片欧美色图| 99久久99久久久精品齐齐| 精品国产91亚洲一区二区三区婷婷 | 色狠狠色狠狠综合| 2欧美一区二区三区在线观看视频| 亚洲最大色网站| av网站一区二区三区| 精品久久久久久综合日本欧美 | 欧美美女一区二区三区| 亚洲欧洲美洲综合色网| 国产成人自拍网| 日韩欧美国产电影| 日av在线不卡| 在线综合视频播放| 午夜精品久久久久久不卡8050| 色哟哟精品一区| 最新日韩av在线| 白白色 亚洲乱淫| 1024精品合集| 91麻豆蜜桃一区二区三区| 综合久久久久综合| 97久久人人超碰| 亚洲精品免费在线观看| 日本精品一区二区三区四区的功能| 中文字幕国产精品一区二区| 成人黄色小视频在线观看| 国产女人水真多18毛片18精品视频| 国产夫妻精品视频| 中文字幕日韩精品一区| 91免费观看国产| 夜夜嗨av一区二区三区网页| 欧洲人成人精品| 日产国产欧美视频一区精品| 日韩一级片网址| 国产做a爰片久久毛片 | 欧美成人猛片aaaaaaa| 极品少妇一区二区| 国产欧美一区二区精品婷婷| 成人av网站在线观看免费| 中文字幕亚洲不卡| 欧美日韩成人综合| 久久se精品一区二区| 国产精品萝li| 欧美日韩mp4| 国产中文字幕一区| 亚洲男人的天堂av| 777奇米四色成人影色区| 久久国产乱子精品免费女| 国产精品麻豆久久久| 欧美日韩精品综合在线| 久久成人综合网| 中文字幕在线免费不卡| 在线播放中文字幕一区| 国产乱码字幕精品高清av | 久久国产精品第一页| 国产精品色哟哟| 欧美性猛交一区二区三区精品| 蜜桃视频一区二区| 亚洲九九爱视频| 精品久久久网站| 99精品欧美一区二区蜜桃免费| 日韩精品一二三| 国产精品久久久久精k8| 欧美一区二区三区视频在线| 成人性生交大片免费看在线播放| 一区二区免费视频| 国产拍揄自揄精品视频麻豆| 欧美日韩激情一区| 成人毛片视频在线观看| 蜜臀av性久久久久蜜臀aⅴ| 亚洲欧洲成人精品av97| 久久综合成人精品亚洲另类欧美| 色综合天天在线| 懂色av一区二区在线播放| 日韩高清国产一区在线| 亚洲另类在线一区| 国产精品色哟哟网站| 精品久久人人做人人爽| 91精品婷婷国产综合久久性色 | 亚洲成人av资源| 亚洲男女一区二区三区| 国产无一区二区| 精品久久一二三区| 欧美精品 日韩| 欧美午夜精品理论片a级按摩| aaa欧美大片| 风流少妇一区二区| 精品一区二区日韩| 奇米四色…亚洲| 日韩不卡一区二区三区| 一区二区三区.www| 亚洲欧美日韩久久| 国产精品激情偷乱一区二区∴| 一区二区三区在线播| 国产亲近乱来精品视频| 欧美精品一区二区三区久久久 | 日韩精品亚洲专区| 亚洲大片精品永久免费| 亚洲综合av网| 一级中文字幕一区二区| 亚洲欧美激情小说另类| 日韩一区有码在线| 国产精品国产三级国产普通话99| 国产精品精品国产色婷婷| 国产精品久久久久久久午夜片| 国产欧美视频一区二区三区| 中文字幕不卡在线| 亚洲欧美一区二区视频| 亚洲天堂成人在线观看| 亚洲美女视频一区| 亚洲午夜激情av| 婷婷激情综合网| 日产国产高清一区二区三区| 精品一区二区三区蜜桃| 国产精品一卡二卡| 成人午夜电影网站| 色哟哟日韩精品| 欧美乱妇20p| 久久久久久电影| 亚洲人成7777| 亚洲第一激情av| 极品少妇xxxx精品少妇偷拍 | 国产揄拍国内精品对白| 国产美女主播视频一区| 成人毛片在线观看| 在线看国产一区| 日韩欧美黄色影院| 日本一区二区三区免费乱视频| 日韩一区欧美小说| 日本亚洲免费观看| 国产美女av一区二区三区| 99久久伊人久久99| 欧美日韩一区二区三区四区| 亚洲精品在线观看视频| 国产精品成人一区二区艾草| 亚洲午夜精品网| 国产精品亚洲第一区在线暖暖韩国| 9色porny自拍视频一区二区| 91精品蜜臀在线一区尤物| 中文字幕二三区不卡| 亚洲一区二区视频| 国内精品久久久久影院薰衣草| 99久精品国产| 亚洲精品一区二区三区蜜桃下载| 亚洲丝袜精品丝袜在线| 久久精品国产亚洲a| 日本韩国欧美在线| 久久久美女毛片| 视频一区在线播放| av网站免费线看精品| 欧美不卡123| 夜夜嗨av一区二区三区中文字幕| 国产精品亚洲第一| 91精品国产麻豆国产自产在线| 国产精品无遮挡| 喷水一区二区三区| 91福利社在线观看| 水蜜桃久久夜色精品一区的特点| 国产一区二区0| 欧美一区二区三区男人的天堂| 日韩一区有码在线| 国产成人亚洲综合a∨猫咪| 欧美一级一级性生活免费录像| 亚洲日本va午夜在线电影| 国产精一区二区三区| 欧美一区二区三区视频在线| 亚洲综合一区在线| 国产成a人亚洲精品| 日韩一二三区视频| 午夜精品在线看| 欧美午夜寂寞影院| 亚洲三级电影网站| 99国产精品国产精品毛片| 欧美激情中文字幕一区二区| 久久99久久99精品免视看婷婷| 欧美色倩网站大全免费| 亚洲专区一二三| 日本韩国精品在线| 亚洲欧美日韩在线不卡| 91在线观看一区二区| 国产精品久久久久久亚洲毛片| 国产成人精品综合在线观看| 欧美精品一区二区三区一线天视频 | 国产成人在线免费观看| 久久久不卡影院| 国产一区二区成人久久免费影院 | 亚洲乱码精品一二三四区日韩在线| 成人深夜视频在线观看| 欧美国产乱子伦| 不卡电影免费在线播放一区| 国产日韩欧美在线一区| 丁香六月综合激情|