📄 frmserver.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 frmServer
BackColor = &H8000000A&
BorderStyle = 4 'Fixed ToolWindow
Caption = "Server Application (File Transfer using MS Winsock 6.0) "
ClientHeight = 4500
ClientLeft = 30
ClientTop = 330
ClientWidth = 5400
FillColor = &H00FFFFFF&
BeginProperty Font
Name = "Times New Roman"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000013&
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4500
ScaleWidth = 5400
ShowInTaskbar = 0 'False
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdClear
Caption = "Clear"
Height = 252
Left = 4320
TabIndex = 8
Top = 3840
Width = 972
End
Begin VB.CommandButton cmdSend
Caption = "发送"
Height = 252
Left = 4200
TabIndex = 7
Top = 1200
Width = 972
End
Begin VB.CommandButton cmdBrowse
Caption = "浏览"
Height = 252
Left = 4200
TabIndex = 6
Top = 360
Width = 972
End
Begin VB.TextBox txtFileName
Height = 300
Left = 120
TabIndex = 4
Top = 360
Width = 3615
End
Begin MSWinsockLib.Winsock tcpServer
Left = 4800
Top = 600
_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 = 252
Left = 4200
TabIndex = 2
Top = 1560
Width = 972
End
Begin VB.TextBox txtView
Height = 1332
Left = 50
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 2400
Width = 5292
End
Begin VB.Label Label3
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "File to send:"
Height = 204
Index = 0
Left = 120
TabIndex = 5
Top = 120
Width = 840
End
Begin VB.Label lblStatus
BorderStyle = 1 'Fixed Single
Caption = " 状态:监听中"
Height = 252
Left = 48
TabIndex = 3
Top = 4200
Width = 5292
End
Begin VB.Label Label1
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "到达数据监视:"
Height = 225
Left = 120
TabIndex = 1
Top = 2160
Width = 1260
End
End
Attribute VB_Name = "frmServer"
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()
Unload Me
End Sub
Private Sub cmdSend_Click()
Dim FName_Only As String
If txtFileName = "" Then
MsgBox "没有选择要发送的文件", vbCritical
Else
If frmServer.tcpServer.State <> sckClosed Then
FName_Only$ = GetFileName(txtFileName)
SendFile FName_Only$
End If
End If
End Sub
Private Sub Form_Load()
tcpServer.LocalPort = Port
tcpServer.Listen
bInconnection = False
Status "监听中…没有连接"
End Sub
Private Sub Form_Unload(Cancel As Integer)
SendData "服务器关闭!"
Pause 500
tcpServer.Close
End
End Sub
Private Sub tcpServer_Close()
If tcpServer.State <> sckClosed Then tcpServer.Close
Form_Load
End Sub
Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
On Error GoTo IDERROR
If tcpServer.State <> sckClosed Then tcpServer.Close
tcpServer.Accept requestID
bInconnection = True
Status "监听中…已经连接"
SendData "Accepted,"
Exit Sub
IDERROR:
MsgBox Err.Description, vbCritical
End Sub
Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
Dim Command As String
Dim NewArrival As String
Dim Data As String
Static DataCnt As Long
tcpServer.GetData NewArrival$, vbString
Command = EvalData(NewArrival$, 1)
Data$ = EvalData(NewArrival$, 2)
Select Case Command$
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 + -