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

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

?? ch20.htm

?? 好的教程Vc++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一区二区三区免费野_久草精品视频
一区二区三区四区视频精品免费| 日韩精品1区2区3区| 91 com成人网| 成人激情文学综合网| 日韩一区欧美二区| 国产精品久久久久一区 | 91精品国产综合久久小美女| 国产福利精品一区二区| 日韩电影在线观看电影| 亚洲色图欧洲色图| 国产欧美精品在线观看| 精品国产伦理网| 911精品国产一区二区在线| 一本到一区二区三区| 国产成人夜色高潮福利影视| 毛片av一区二区| 视频一区在线视频| 亚洲v中文字幕| 亚洲日本在线a| 亚洲国产成人一区二区三区| 欧美不卡视频一区| 欧美一区二区三区视频免费播放 | 精品欧美一区二区三区精品久久| 色综合久久久久久久| 不卡视频一二三| 成人免费高清在线观看| 粉嫩在线一区二区三区视频| 久久国产精品色婷婷| 日本不卡视频在线观看| 亚洲午夜电影网| 亚洲综合在线视频| 亚洲综合视频在线| 亚洲国产成人精品视频| 亚洲综合久久久| 亚洲最新视频在线播放| 一区二区三区在线视频免费| 亚洲人成人一区二区在线观看 | 美女网站在线免费欧美精品| 日韩电影免费在线看| 男男gaygay亚洲| 男人的天堂久久精品| 另类小说综合欧美亚洲| 国产一区在线观看视频| 国产自产2019最新不卡| 国产曰批免费观看久久久| 国产一区啦啦啦在线观看| 国产在线精品一区二区三区不卡 | 国产东北露脸精品视频| 国产91精品入口| 99久久久久久| 欧美午夜在线观看| 日韩视频免费观看高清完整版在线观看| 欧美一区二区三区喷汁尤物| 欧美大尺度电影在线| 久久久久久久久一| 中文字幕一区二区日韩精品绯色| 亚洲免费在线看| 亚洲超碰精品一区二区| 美女视频黄 久久| 国产高清不卡一区| 一本色道久久综合亚洲精品按摩| 欧美色男人天堂| 日韩三级精品电影久久久| 久久亚洲综合色| 国产精品成人免费精品自在线观看 | 亚洲成在人线在线播放| 日韩中文欧美在线| 国产精品亚洲一区二区三区妖精 | 在线播放中文字幕一区| 欧美成人激情免费网| 国产精品午夜免费| 亚洲国产精品久久人人爱蜜臀| 日韩电影一区二区三区四区| 国产xxx精品视频大全| 在线观看视频欧美| 26uuu亚洲| 一区二区高清视频在线观看| 美女精品自拍一二三四| 懂色av一区二区三区免费观看| 日本韩国精品在线| 精品欧美黑人一区二区三区| 亚洲欧美国产77777| 久久99精品久久久久久| 91视视频在线观看入口直接观看www | 欧美国产视频在线| 午夜精品久久久久久久久| 国产精品一区二区久激情瑜伽| 91免费看片在线观看| 日韩欧美国产午夜精品| 亚洲人被黑人高潮完整版| 首页亚洲欧美制服丝腿| 成人手机电影网| 69堂精品视频| 亚洲天堂免费在线观看视频| 久久99久久久久久久久久久| 91玉足脚交白嫩脚丫在线播放| 日韩免费视频一区| 一级做a爱片久久| 成人免费观看视频| 日韩你懂的在线播放| 亚洲精品日韩综合观看成人91| 国产精品影视在线观看| 777xxx欧美| 亚洲国产中文字幕在线视频综合| 国产91色综合久久免费分享| 日韩欧美在线一区二区三区| 亚洲综合在线第一页| gogo大胆日本视频一区| 久久久一区二区三区| 轻轻草成人在线| 欧美日韩在线播放| 一区二区三区国产精品| 97超碰欧美中文字幕| 国产日产精品1区| 极品少妇一区二区| 日韩三级视频中文字幕| 午夜精品视频在线观看| 97精品久久久午夜一区二区三区| 国产欧美一区二区三区在线看蜜臀| 日韩av二区在线播放| 欧美三级资源在线| 亚洲资源在线观看| 91麻豆国产福利精品| 国产精品国产三级国产专播品爱网 | 午夜日韩在线观看| 在线影院国内精品| 一区二区三区免费观看| 91丨九色丨尤物| 中文字幕中文乱码欧美一区二区| 成人自拍视频在线| 久久免费精品国产久精品久久久久| 老司机免费视频一区二区| 欧美一区二区免费| 日韩高清不卡在线| 在线91免费看| 久久精品国产精品亚洲精品| 91精品国产综合久久国产大片| 亚洲尤物视频在线| 欧美日韩国产a| 日韩高清国产一区在线| 欧美一级夜夜爽| 老鸭窝一区二区久久精品| 欧美电影免费提供在线观看| 美女被吸乳得到大胸91| 欧美zozozo| 国产成人av网站| 国产精品理论片在线观看| 成人h版在线观看| 亚洲三级在线播放| 欧美男生操女生| 久久99精品久久只有精品| 久久久影视传媒| 色综合激情久久| 日本欧美肥老太交大片| 2023国产精品| 欧美美女喷水视频| 日韩不卡手机在线v区| 日韩亚洲欧美中文三级| 国产精品77777| 一区二区国产盗摄色噜噜| 日韩欧美视频在线| 成人av电影在线| 性欧美疯狂xxxxbbbb| 精品国产a毛片| eeuss鲁一区二区三区| 一区二区三区在线免费播放| 6080yy午夜一二三区久久| 国产成人av一区二区| 亚洲一区二区在线视频| 欧美videofree性高清杂交| 不卡av电影在线播放| 天堂av在线一区| 国产精品美女久久久久aⅴ国产馆| 在线欧美日韩国产| 国产综合色视频| 亚洲精品日韩专区silk| 精品国产一区a| 91国产成人在线| 韩国av一区二区三区四区 | 日本不卡一区二区三区| 国产日韩成人精品| 欧美日韩一级二级三级| 国产麻豆精品在线观看| 亚洲国产精品人人做人人爽| 国产色一区二区| 91精品国产手机| 一本久久精品一区二区| 激情五月婷婷综合| 性做久久久久久免费观看| 中文字幕精品综合| 欧美成人一区二区三区片免费| 国产99久久久国产精品潘金| 石原莉奈一区二区三区在线观看| 国产亚洲美州欧州综合国| 欧美日韩一区精品| a级高清视频欧美日韩| 精品一区二区免费在线观看| 亚洲不卡在线观看| 亚洲乱码国产乱码精品精小说| 亚洲精品一线二线三线无人区|