📄 form_multitcp.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Frm_MultiTCP
Caption = "多客户连接"
ClientHeight = 4350
ClientLeft = 60
ClientTop = 345
ClientWidth = 5220
LinkTopic = "Form1"
ScaleHeight = 4350
ScaleWidth = 5220
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
Height = 3135
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 2
Top = 960
Width = 4815
End
Begin VB.CommandButton Command1
Caption = "发送信息"
Height = 375
Left = 3720
TabIndex = 1
Top = 120
Width = 1215
End
Begin VB.TextBox Text1
Height = 375
Left = 120
TabIndex = 0
Top = 120
Width = 3375
End
Begin MSWinsockLib.Winsock WSK_Server
Index = 0
Left = 2880
Top = 480
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.Label Label1
Caption = "接受到的信息"
Height = 255
Left = 120
TabIndex = 3
Top = 600
Width = 2175
End
End
Attribute VB_Name = "Frm_MultiTCP"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ClientNum As Integer
Private Sub Command1_Click()
Dim i As Integer
For i = 1 To ClientNum
If Not WSK_Server(i) Is Nothing Then
DoEvents
WSK_Server(i).SendData "服务器:" & Text1.Text
End If
Next
End Sub
Private Sub Form_Load()
WSK_Server(0).LocalPort = 1001
'程序启动时侦听
WSK_Server(0).Listen
End Sub
Private Sub WSK_Server_Close(Index As Integer)
Set WSK_Server(Index) = Nothing
End Sub
Private Sub WSK_Server_ConnectionRequest(Index As Integer, ByVal requestID As Long)
ClientNum = ClientNum + 1
Load WSK_Server(ClientNum) '载入一个新的socket控件
WSK_Server(ClientNum).Accept requestID '接受客户端的请求
WSK_Server(ClientNum).SendData "欢迎光临!!"
End Sub
Private Sub WSK_Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim myData As String
WSK_Server(Index).GetData myData
Text2.Text = Text2.Text + myData + vbCrLf
End Sub
Private Sub WSK_Server_Error(Index As Integer, ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
WSK_Server(Index).Close
Set WSK_Server(Index) = Nothing
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -