📄 frmclient.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form frmClient
BackColor = &H80000000&
BorderStyle = 4 'Fixed ToolWindow
Caption = "文件传输-客户"
ClientHeight = 4500
ClientLeft = 30
ClientTop = 330
ClientWidth = 5400
BeginProperty Font
Name = "Times New Roman"
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 = 4500
ScaleWidth = 5400
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdClear
Caption = "清除"
Height = 252
Left = 4320
TabIndex = 10
Top = 3840
Width = 972
End
Begin VB.TextBox txtView
Height = 1332
Left = 50
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 8
Top = 2400
Width = 5292
End
Begin VB.CommandButton cmdDisconnect
Caption = "断开"
Height = 375
Left = 240
TabIndex = 7
Top = 1320
Width = 1095
End
Begin VB.CommandButton cmdConnect
Caption = "连接"
Height = 375
Left = 240
TabIndex = 6
Top = 840
Width = 1095
End
Begin VB.CommandButton cmdSend
Caption = "发送"
Height = 375
Left = 2640
TabIndex = 5
Top = 840
Width = 1095
End
Begin VB.CommandButton cmdBrowse
Caption = "浏览"
Height = 375
Left = 4200
TabIndex = 4
Top = 360
Width = 972
End
Begin VB.TextBox txtFileName
Height = 300
Left = 120
TabIndex = 2
Top = 360
Width = 3615
End
Begin MSWinsockLib.Winsock tcpClient
Left = 4440
Top = 120
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSComDlg.CommonDialog cdOpen
Left = 4800
Top = 120
_ExtentX = 688
_ExtentY = 688
_Version = 393216
End
Begin VB.CommandButton cmdClose
Caption = "关闭"
Height = 375
Left = 2640
TabIndex = 0
Top = 1320
Width = 1095
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "文件传递监视:"
ForeColor = &H80000007&
Height = 225
Left = 120
TabIndex = 9
Top = 2160
Width = 1260
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "要发送文件:"
ForeColor = &H80000008&
Height = 225
Index = 0
Left = 120
TabIndex = 3
Top = 120
Width = 1080
End
Begin VB.Label lblStatus
BorderStyle = 1 'Fixed Single
Caption = " 状态:没有连接"
Height = 252
Left = 48
TabIndex = 1
Top = 4200
Width = 5292
End
End
Attribute VB_Name = "frmClient"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub cmdClear_Click()
txtView = ""
txtFileName = ""
End Sub
Private Sub cmdClose_Click()
End
End Sub
Private Sub cmdConnect_Click()
bReplied = False
tcpClient.Connect "127.0.0.1", 2001
lTIme = 0
While (Not bReplied) And (lTIme < 100000)
DoEvents
lTIme = lTIme + 1
Wend
If lTIme >= 100000 Then
MsgBox "不能连接到服务器!", vbCritical, "连接错误"
tcpClient.Close
Exit Sub
End If
End Sub
Private Sub cmdDisconnect_Click()
tcpClient.Close
Form_Load
End Sub
Private Sub cmdSend_Click()
Dim FName_Only As String
If txtFileName = "" Then
MsgBox "没有选择文件", vbCritical
Else ' 发送文件
If tcpClient.State <> sckClosed Then
FName_Only$ = GetFileName(txtFileName)
SendFile FName_Only$
End If
End If
End Sub
Private Sub Form_Load()
Status "Disconnected."
bReplied = False
End Sub
Private Sub tcpClient_Close()
If tcpClient.State <> sckClosed Then tcpClient.Close
End Sub
Private Sub tcpClient_DataArrival(ByVal bytesTotal As Long)
Dim Command As String
Dim NewArrival As String
Dim Data As String
Static DataCnt As Long
tcpClient.GetData NewArrival$, vbString
Command$ = EvalData(NewArrival$, 1)
Data$ = EvalData(NewArrival$, 2)
Select Case Command
Case "Accepted" '服务器接收连接
bReplied = True
Status "已经连接"
Case "ServerClosed" '服务器关闭
Form_Load
tcpClient.Close
Case "OpenFile" ' 打开文件
Dim Fname As String
Fname$ = App.Path & "\" & Data$
Open Fname$ For Binary As #1
Status "打开文件…" & Data$
Case "CloseFile" ' 关闭文件
' 文件传递完毕
Close #1
Status "文件传递完毕…"
Pause 3000
Status "已经连接"
Case Else '写入文件
Put #1, , NewArrival$
txtView = txtView & NewArrival$
DataCnt& = DataCnt& + 1
Status "获得文件中…" & (MAX_CHUNK * DataCnt&) & " bytes"
End Select
End Sub
Private Sub cmdBrowse_Click()
cdOpen.ShowOpen
If Not vbCancel Then
txtFileName = cdOpen.FileName
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -