我是编码的初学者,我试图理解我的教授给我的这组代码。以下是表单的完整代码:
Option Explicit
Private Sub cmdSend_Click()
Dim sIPAddress As String
sIPAddress = Trim(txtIPAddress)
If sIPAddress = "" Then Exit Sub
With Winsock1
.RemoteHost = sIPAddress
.RemotePort = "1338"
.SendData txtSendMessage
End With
End Sub
Private Sub Form_Load()
With Winsock1
.Close
.Protocol = sckUDPProtocol
.Bind "1337"
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim msg As String
Winsock1.GetData msg, vbString
txtReceiveMessage = msg & vbCrLf & txtReceiveMessage
End Sub
这是我无法理解的代码:
With Winsock1
.RemoteHost = sIPAddress
.RemotePort = "1338"
.SendData txtSendMessage
End With
End Sub
Private Sub Form_Load()
With Winsock1
.Close
.Protocol = sckUDPProtocol
.Bind "1337"
End With
End Sub
有人能让我明白吗?当我在接下来的几十年或两年中遇到这些代码时,一个单词的意义将更好地使我的生活更轻松。感谢。
答案 0 :(得分:1)
当表单加载时,调用Form_Load()并将Winsock的协议设置为UDP并侦听(绑定)端口1337上的输入。
表单上有一个按钮(cmdSend)。单击它时,它会发送txtSendMessage文本框的内容。