📄 winsockclient.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form ClientFrm
AutoRedraw = -1 'True
Caption = "Client"
ClientHeight = 3750
ClientLeft = 3795
ClientTop = 1905
ClientWidth = 4110
LinkTopic = "Form1"
ScaleHeight = 3750
ScaleWidth = 4110
Tag = "hello"
Begin VB.TextBox Text1
Height = 2415
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 0
Width = 3855
End
Begin VB.TextBox Text2
Height = 855
Left = 120
MultiLine = -1 'True
TabIndex = 2
Top = 2520
Width = 3855
End
Begin VB.CommandButton Command2
Caption = "退出"
Height = 255
Left = 2640
TabIndex = 1
Top = 3480
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "发送"
Height = 255
Left = 240
TabIndex = 0
Top = 3480
Width = 1215
End
Begin MSWinsockLib.Winsock SockCL
Left = 1800
Top = 3360
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
End
Attribute VB_Name = "ClientFrm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim SendMsg As String
Private Sub Form_Load()
' 指定服务器主机名
SockCL.RemoteHost = "127.0.0.1"
' 指定服务器端口名
SockCL.RemotePort = 2000
' 连接到服务器
SockCL.Connect
End Sub
Private Sub SockCl_DataArrival(ByVal bytesTotal As Long)
Dim DataStr As String
' 接收数据到文本框中
SockCL.GetData DataStr
If Text1.Text = "" Then
Text1.Text = "From Server: " & DataStr
Else
Text1.Text = Text1.Text & vbCrLf & "From Server: " & DataStr
End If
End Sub
' 向服务器发送数据
Private Sub Command1_Click()
SendMsg = Text2.Text
SockCL.SendData SendMsg
End Sub
' 发送完毕后回显
Private Sub SockCL_SendComplete()
If Text1.Text = "" Then
Text1.Text = "To Server: " & SendMsg
Else
Text1.Text = Text1.Text & vbCrLf & "To Server: " & SendMsg
End If
End Sub
' 退出程序
Private Sub Command2_Click()
SockCL.Close
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -