Windows Socket網路編程學習筆記一

來源:互聯網
上載者:User
作者:朱金燦

來源:blog.csdn.net/clever101

 

 

 

如何理解Windows Socket?

 

我的理解:Windows Socket相當於Windows平台上兩個網路實體開闢的一條通訊通道,這條通訊通道的實現細節對網路雙方是不可見的(呵呵,你就知道它是Windows製造)。通過這條通道,網路雙方可以傳輸各種資料。

 

你可能急不可待地問這條通道是怎樣開闢的呢?下面我以伺服器段和用戶端作為網路雙方進行說明。請看:


 這樣你看明白了嗎?伺服器和用戶端之間的串連實際上是伺服器端Socket和用戶端Socket之間的串連。那麼在程式中具體如何呢?實際上很簡單,就是在伺服器端程式建立一個Socket類對象,在用戶端程式建立一個Socket類對象,然後把串連、資料轉送等網路通訊等工作交給他倆去做。

 

瞭解了Socket通訊模型,你是不是覺得Windows Socket網路編程不像想象中那麼難呢?然後你可以去瞭解MFC中的Socket類CAsyncSocket和CSocket類的用法,建議你重點看看那篇《Windows Sockets:
Socket Notifications》以及下面的

宋體;mso-font-kerning:0pt">•   Windows
Sockets: Using Class CAsyncSocket

宋體;mso-font-kerning:0pt">•   Windows
Sockets: Deriving from Socket Classes

宋體;mso-font-kerning:0pt">•   Windows
Sockets: How Sockets with Archives Work

宋體;mso-font-kerning:0pt">•   Windows
Sockets: Blocking

宋體;mso-font-kerning:0pt">•   Windows
Sockets: Byte Ordering

宋體;mso-font-kerning:0pt">•   Windows
Sockets: Converting Strings

    mso-bidi-font-family:宋體;mso-font-kerning:0pt">    mso-bidi-font-family:宋體;mso-font-kerning:0pt">其實MFC中的Socket類和CWnd類有一點是相似的,就是有一些訊息激發函數。你需要理解什麼條件下這些函數會響應。最後我建議你看懂《Windows Sockets: Socket Notifications》的常式(點擊Samplemso-hansi-font-family:"Times New Roman"'>連結),那是一個簡單的聊天程式,這對理解Socketmso-hansi-font-family:"Times New Roman"'>很有好處(我就是從那得到啟發的)。

    相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.