⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmclient.frm

📁 本程序使用VB语言编程
💻 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       =   &H00C0C0FF&
   BorderStyle     =   4  'Fixed ToolWindow
   Caption         =   "文件传输,客户端程序!"
   ClientHeight    =   5265
   ClientLeft      =   30
   ClientTop       =   330
   ClientWidth     =   6510
   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     =   5265
   ScaleWidth      =   6510
   ShowInTaskbar   =   0   'False
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   2040
      TabIndex        =   11
      Top             =   1440
      Width           =   1695
   End
   Begin MSComDlg.CommonDialog cdOpen 
      Left            =   5880
      Top             =   120
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton cmdClear 
      Caption         =   "清除"
      Height          =   252
      Left            =   5280
      TabIndex        =   10
      Top             =   4560
      Width           =   972
   End
   Begin VB.TextBox txtView 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1332
      Left            =   50
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   8
      Top             =   3000
      Width           =   6375
   End
   Begin VB.CommandButton cmdDisconnect 
      Caption         =   "关闭连接"
      Height          =   252
      Left            =   3360
      TabIndex        =   7
      Top             =   2040
      Width           =   972
   End
   Begin VB.CommandButton cmdConnect 
      Caption         =   "连接"
      Height          =   252
      Left            =   2160
      TabIndex        =   6
      Top             =   2040
      Width           =   972
   End
   Begin VB.CommandButton cmdSend 
      Caption         =   "发送"
      Height          =   252
      Left            =   5160
      TabIndex        =   5
      Top             =   1800
      Visible         =   0   'False
      Width           =   972
   End
   Begin VB.CommandButton cmdBrowse 
      Caption         =   "浏览..."
      Height          =   252
      Left            =   5160
      TabIndex        =   4
      Top             =   1200
      Visible         =   0   'False
      Width           =   972
   End
   Begin VB.TextBox txtFileName 
      Height          =   300
      Left            =   120
      TabIndex        =   2
      Top             =   480
      Width           =   6135
   End
   Begin MSWinsockLib.Winsock tcpClient 
      Left            =   4440
      Top             =   120
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.CommandButton cmdClose 
      Caption         =   "关闭"
      Height          =   252
      Left            =   5160
      TabIndex        =   0
      Top             =   2400
      Width           =   972
   End
   Begin VB.Shape Shape1 
      BorderColor     =   &H00FF0000&
      BorderWidth     =   3
      Height          =   1575
      Left            =   120
      Top             =   960
      Width           =   4695
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "服务器IP:"
      ForeColor       =   &H00000000&
      Height          =   225
      Index           =   1
      Left            =   840
      TabIndex        =   12
      Top             =   1440
      Width           =   750
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "连接信息:"
      ForeColor       =   &H00000000&
      Height          =   225
      Left            =   120
      TabIndex        =   9
      Top             =   2640
      Width           =   765
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "选择要发送的文件:"
      ForeColor       =   &H00000000&
      Height          =   225
      Index           =   0
      Left            =   120
      TabIndex        =   3
      Top             =   120
      Width           =   1485
   End
   Begin VB.Label lblStatus 
      BorderStyle     =   1  'Fixed Single
      Caption         =   " 状态 : 连接"
      Height          =   255
      Left            =   45
      TabIndex        =   1
      Top             =   4920
      Width           =   6375
   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()
        
    'try to make a connection to the Server.
    
    bReplied = False
    tcpClient.Connect Text1.Text, 1256
    
    lTIme = 0
    
    While (Not bReplied) And (lTIme < 100000)
        DoEvents
        lTIme = lTIme + 1
    Wend
    
    
    If lTIme >= 100000 Then
        'Didn't reply or timed out. close the connection
        MsgBox "Unable to connect to remote server", vbCritical, "Connection Error"
        
        tcpClient.Close
        Exit Sub
    End If
    cmdBrowse.Visible = True
    cmdSend.Visible = True
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 "No file selected to send...", vbCritical
    Else ' send the file, if connected
       If tcpClient.State <> sckClosed Then
          ' send only the file name because it will
          ' be stored in another area than the source
          FName_Only$ = GetFileName(txtFileName)
          SendFile FName_Only$
       End If
    End If
End Sub

Private Sub Form_Load()
    Status "Disconnected."
    bReplied = False
End Sub

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'   G E N E R A L   W I N S O C K   P R O C W D U R E S
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Private Sub tcpClient_Close()
    '
    'Socket got a close call so close it if it's not already closed
    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
    
    ' Extract the command from the Left
    ' of the comma (default divider)
    Command$ = EvalData(NewArrival$, 1)
    ' extract the data being sent from the
    ' right of the comma (default divider)
    Data$ = EvalData(NewArrival$, 2)
    
    ' execute according to command sent
    Select Case Command
        Case "Accepted"          ' server accepted connection
             bReplied = True
             Status "Connected."
             
             ' this is a good practice.
             ' when the server has been closed
             ' theclient is notified here.
             ' and immediatley disconnected.
        Case "ServerClosed"
             Form_Load
             tcpClient.Close
             
        Case "OpenFile"  ' open the file
           Dim Fname As String
           
           ' the file name only should've been sent
           Fname$ = App.Path & "\" & Data$
           Open Fname$ For Binary As #1
           ' file now opened to recieve input
           Status "File opened.... " & Data$
               
        Case "CloseFile" ' close the file
           ' all data has been sent, close the file
           Close #1
           Status "File Transfer complete..."
           Pause 3000
           Status "Connected."
                
       ' when sending a file.... it is best not to Name
       ' the Case instead use ELse for file transfer
            
        Case Else
           ' write the incoming chunk of data to the
           ' opened file
           Put #1, , NewArrival$
           ' update the view port with the new addition
' ** // ** '
' IMPORTANT: comment out the code below when sending files
' larger than 500Kb. It makes the function CRAWL otherwise
              
           txtView = txtView & NewArrival$
' comment the above line to increase speed
        
           ' count and report the incoming chunks
           DataCnt& = DataCnt& + 1
           Status "Recieving Data... " & (MAX_CHUNK * DataCnt&) & " bytes"
            
    End Select
    
End Sub
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
'  end  G E N E R A L   W I N S O C K   P R O C W D U R E S  end
'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\







Private Sub cmdBrowse_Click()
    ' show the Open Dialog for the user to select a file.
    cdOpen.ShowOpen
    
    If Not vbCancel Then
       txtFileName = cdOpen.FileName
    End If
    
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -