1 / 23

在 Ad-hoc 網路中實現點對點發送訊息與廣播訊息

在 Ad-hoc 網路中實現點對點發送訊息與廣播訊息. 檔案下載. 範例程式可 在下列網址 取得 http://www.cc.chu.edu.tw/~ m09702044/ADHOC/DEMO_Code.zip http ://ppt.cc/Oyj ! DEMO 程式 可在下列網址取得 http://www.cc.chu.edu.tw/~m09702044/ADHOC/UDP_Demo.exe http :// ppt.cc/P57f 投影片可 在下列網址取得 http://www.cc.chu.edu.tw/~ m09702044/ADHOC/ADHOCUDP.pptx

Télécharger la présentation

在 Ad-hoc 網路中實現點對點發送訊息與廣播訊息

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 在Ad-hoc網路中實現點對點發送訊息與廣播訊息

  2. 檔案下載 • 範例程式可在下列網址取得 • http://www.cc.chu.edu.tw/~m09702044/ADHOC/DEMO_Code.zip • http://ppt.cc/Oyj! • DEMO程式可在下列網址取得 • http://www.cc.chu.edu.tw/~m09702044/ADHOC/UDP_Demo.exe • http://ppt.cc/P57f • 投影片可在下列網址取得 • http://www.cc.chu.edu.tw/~m09702044/ADHOC/ADHOCUDP.pptx • http://ppt.cc/W@54

  3. 目的 • 在Ad-hoc網路中實現點對點發送訊息與廣播訊息。 • 使用 UDP通訊協定與網路服務通訊。 • 利用UdpClient類別,UdpClient類別的屬性和方法摘要了建立 Socket 以使用 UDP 要求與接收資料時,所需的詳細資料。

  4. 程式介面 • 使用者輸入 • textBox2 • textBox3 • textBox4 • richTextBox3

  5. 命名空間和定義 • using System.Net; • using System.Net.Sockets;

  6. 程式介面

  7. 本機IP位址 • 可利用本機的hostname來取得IP address • 取得hostname • String LocalHostName = Dns.GetHostName() • 取得IP address • IPHostEntryipInfor = Dns.GetHostEntry(LocalHostName)

  8. 程式介面

  9. 開始監聽 (button1) • 設定通訊埠。(port) • 新建立UdpClient並監聽通訊埠等待接收訊息。 (receivingUdpClient = new ???) • 設定client的IPEndPoint,允許接收來自任何來源端傳送的訊息。(RemoteIpEndPoint = new ???) • 呼叫WaitForData() 開始接收資料。

  10. 定義UdpClient_State • 定義buffer的大小和目前的socket

  11. WaitForData ()(等待接收資料) • 檢查是否已經接收完訊息: • 如果已經接收完訊息 • 在非同步作業完成時呼叫的回呼方法。(呼叫ReadCallback來處理接收到的訊息,readAsyCallBack = new ???(???))

  12. WaitForData ()(等待接收資料) • 檢查是否已經接收完訊息: • 如果尚未接收完訊息 • 替Client新建立UdpClient_state • 開始使用非同步接收來自 client 的訊息。(recvsocket.???(???, ???))

  13. ReadCallback ()(處理接收到的訊息) • 建立UdpClient_state來處理 client 的回應 • 結束讀取接收到的訊息。(bytesRead2 = ???.???.??? (???, ???)) • 儲存接收到的訊息。(showtxt)

  14. ReadCallback ()(處理接收到的訊息) • 利用跨執行緒的方法輸出訊息。 • UpdateUI()

  15. 程式介面

  16. 關閉監聽 (button2) • 關閉正在監聽的 socket。(receivingUdpClient.???)

  17. 程式介面

  18. 發送訊息至指定的電腦 (button3) • 設定連線的目的端資訊。(remoteIEP = new ???) • 新建立Udpclient。(udpClientsend = new ???)

  19. 發送訊息至指定的電腦 (button3) • 利用Encoding.Unicode.GetBytes(string s),將輸入的訊息(string)轉換為byte。 (SendbyteData = ???) (例如:" (" + 使用者 + ") 說:\n" + 訊息內容) • 傳送訊息至目的端。(udpClientsend.???(???, ???, ???))

  20. 程式介面

  21. 發送廣播訊息 (button4) • 設定廣播目的地IPEndPoint。(bcastIEP = new ???) • 新建立broadcast的UdpClient。(udpClientbsend = new ???)

  22. 發送廣播訊息 (button4) • 利用Encoding.Unicode.GetBytes(string s),將輸入的訊息(string)轉換為byte。 (bcastSendbyteData = ???) (例如:“ [廣播] (" + 使用者 + ") 說:\n" + 訊息內容) • 傳送訊息至目的端。(udpClientsend.???(???, ???, ???))

  23. 示意圖

More Related