程式設計工藝大師
TCP與UDP差異
傳輸控制協議(Transmission Control Protocol, TCP)是一種連接導向的、可靠的、基於位元組流的運輸層(Transport layer)通信協議
用戶數據報協議(User Datagram Protocol, UDP)是一個簡單的面向數據報的傳輸層協議 ,UDP只提供數據的不可靠傳遞,它一旦把應用程序發給網路層的數據發送出去,就不保留數據備份(所以UDP有時候也被認為是不可靠的數據報協議)
圖片來源 http://blog.yam.com/ibma92157/article/27530306
當SERVER
Option Explicit
Private Sub cmdSend_Click()
Winsock1.SendData txtSend.Text
End Sub
Private Sub Form_Load()
Winsock1.LocalPort = 7777
Winsock1.Listen '監聽
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData, vbString
txtReceived.Text = strData
If strData = "close" Then
Winsock1.Close
cmdSend.Enabled = False
Winsock1.Listen
End If
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
MsgBox "有人敲門"
Winsock1.Close
Winsock1.Accept requestID '改成接受
cmdSend.Enabled = True
End Sub
當CLEINT
Option Explicit
Private Sub cmdSend_Click()
Winsock1.SendData txtSend.Text
End Sub
Private Sub Form_Load()
Winsock1.LocalPort = 7777
Winsock1.Listen '監聽
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
Winsock1.GetData strData, vbString
txtReceived.Text = strData
If strData = "close" Then
Winsock1.Close
cmdSend.Enabled = False
Winsock1.Listen
End If
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
MsgBox "有人敲門"
Winsock1.Close
Winsock1.Accept requestID '改成接受
cmdSend.Enabled = True
End Sub
沒有留言:
張貼留言