📄 frmudpserver.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmUDPServer
Caption = "Simple UDP Server"
ClientHeight = 3750
ClientLeft = 60
ClientTop = 345
ClientWidth = 4710
LinkTopic = "Form1"
ScaleHeight = 3750
ScaleWidth = 4710
StartUpPosition = 3 'Windows Default
Begin MSWinsockLib.Winsock udpServer
Left = 2160
Top = 1680
_ExtentX = 741
_ExtentY = 741
_Version = 393216
Protocol = 1
End
Begin VB.TextBox txtOutput
Height = 3375
Left = 0
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 360
Width = 4695
End
Begin VB.CommandButton cmdSend
Caption = "Send Text"
Height = 285
Left = 3480
TabIndex = 1
Top = 0
Width = 1215
End
Begin VB.TextBox txtSend
Height = 285
Left = 0
TabIndex = 0
Top = 0
Width = 3375
End
End
Attribute VB_Name = "frmUDPServer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 19.15
' A simple server using UDP protocol
Option Explicit
Private Sub Form_Load()
' set up local port and wait for connection
Call udpServer.Bind(5000)
End Sub
Private Sub Form_Terminate()
Call udpServer.Close
End Sub
Private Sub Form_Resize()
On Error Resume Next
Call cmdSend.Move(ScaleWidth - cmdSend.Width, 0)
Call txtSend.Move(0, 0, ScaleWidth - cmdSend.Width)
Call txtOutput.Move(0, txtSend.Height, ScaleWidth, _
ScaleHeight - txtSend.Height)
End Sub
Private Sub udpServer_DataArrival(ByVal bytesTotal As Long)
Dim message As String
Call udpServer.GetData(message) ' get data from client
txtOutput.Text = txtOutput.Text & _
"From: IP address: " & udpServer.RemoteHostIP & _
vbCrLf & "Port #: " & Str$(udpServer.RemotePort) & _
vbCrLf & "Bytes received: " & Str$(bytesTotal) & _
vbCrLf & "Message: " & message & vbCrLf & vbCrLf
txtOutput.SelStart = Len(txtOutput.Text)
End Sub
Private Sub cmdSend_Click()
Call udpServer.SendData(txtSend.Text) ' send data to client
txtOutput.Text = txtOutput.Text & _
"Sent message: " & txtSend.Text & vbCrLf & vbCrLf
txtSend.Text = ""
txtOutput.SelStart = Len(txtOutput.Text)
udpServer.RemotePort = 0
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -