📄 frmserver.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmServer
BorderStyle = 3 'Fixed Dialog
Caption = "Server"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
BeginProperty Font
Name = "Arial"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Begin VB.ListBox lstMessage
Height = 1185
Left = 120
TabIndex = 6
Top = 1680
Width = 4335
End
Begin VB.ComboBox cboProtocol
Height = 345
ItemData = "frmServer.frx":0000
Left = 720
List = "frmServer.frx":000A
Style = 2 'Dropdown List
TabIndex = 5
Top = 90
Width = 1215
End
Begin VB.CommandButton cmdClose
Caption = "停止监听"
Enabled = 0 'False
Height = 495
Left = 1680
TabIndex = 3
Top = 1080
Width = 1215
End
Begin VB.CommandButton cmdListen
Caption = "开始监听"
Height = 495
Left = 240
TabIndex = 1
Top = 1080
Width = 1215
End
Begin MSWinsockLib.Winsock wskServer
Left = 2760
Top = 480
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.TextBox txtPort
Height = 330
Left = 720
TabIndex = 0
Text = "61450"
Top = 600
Width = 1215
End
Begin VB.Label Label2
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "协议:"
Height = 225
Left = 120
TabIndex = 4
Top = 150
Width = 540
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "端口:"
Height = 225
Left = 120
TabIndex = 2
Top = 653
Width = 540
End
End
Attribute VB_Name = "frmServer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdClose_Click()
wskServer.Close '关闭连接和监听
cmdClose.Enabled = False
cmdListen.Enabled = True
End Sub
Private Sub cmdListen_Click()
If (cboProtocol.ListIndex = 0) Then
wskServer.Protocol = sckTCPProtocol 'tcp
wskServer.LocalPort = Val(txtPort.Text) '绑定本地端口
wskServer.Listen '开始监听
Else
wskServer.Protocol = sckUDPProtocol 'udp
wskServer.LocalPort = Val(txtPort.Text) '绑定本地端口
wskServer.Bind '开始监听
End If
cmdClose.Enabled = True
cmdListen.Enabled = False
End Sub
Private Sub Form_Load()
cboProtocol.ListIndex = 0
End Sub
Private Sub wskServer_ConnectionRequest(ByVal requestID As Long)
wskServer.Close
wskServer.Accept requestID 'tcp协议使用,接受客户端连接请求
End Sub
'获取客户端发送过来的消息
Private Sub wskServer_DataArrival(ByVal bytesTotal As Long)
Dim strMessage As String
Dim bytMessage() As Byte
wskServer.GetData bytMessage, vbByte
strMessage = StrConv(bytMessage, vbUnicode)
'Call AddData(strMessage, 1)
lstMessage.AddItem strMessage
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -