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

📄 client.frm

📁 使用winsock控件实现server与client互传数据
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Client :"
   ClientHeight    =   3195
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3195
   ScaleWidth      =   4680
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton Command2 
      Caption         =   "Send"
      Height          =   375
      Left            =   3360
      TabIndex        =   6
      Top             =   1080
      Width           =   975
   End
   Begin VB.CheckBox Check1 
      Caption         =   "CrLf"
      Height          =   300
      Left            =   2520
      TabIndex        =   8
      Top             =   1080
      Width           =   855
   End
   Begin VB.TextBox Text4 
      Height          =   1575
      Left            =   360
      MultiLine       =   -1  'True
      TabIndex        =   7
      Text            =   "client.frx":0000
      Top             =   1560
      Width           =   3975
   End
   Begin VB.TextBox Text3 
      Height          =   375
      Left            =   360
      TabIndex        =   5
      Text            =   "Text3"
      Top             =   1080
      Width           =   2055
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Connect"
      Height          =   375
      Left            =   3360
      TabIndex        =   4
      Top             =   600
      Width           =   975
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   1920
      TabIndex        =   2
      Text            =   "9000"
      Top             =   600
      Width           =   1335
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1920
      TabIndex        =   0
      Text            =   "127.0.0.1"
      Top             =   120
      Width           =   2415
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   120
      Top             =   360
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label Label2 
      Caption         =   "Server Port :"
      Height          =   255
      Left            =   360
      TabIndex        =   3
      Top             =   600
      Width           =   1335
   End
   Begin VB.Label Label1 
      Caption         =   "Server IP :"
      Height          =   255
      Left            =   360
      TabIndex        =   1
      Top             =   120
      Width           =   1095
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim IsConnectionOpen As Boolean

Private Sub Command1_Click()
On Error GoTo er
    Winsock1.RemoteHost = Text1.Text
    Winsock1.RemotePort = CLng(Text2.Text)
    Winsock1.Connect
    Exit Sub
er:
    Winsock1.Close
End Sub

Private Sub Command2_Click()
    Dim s As String
    If IsConnectionOpen = False Then
        MsgBox "未建立联接!"
    Else
        s = Text3
        If Check1 Then s = s + vbCrLf
        Winsock1.SendData s
    End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Winsock1.Close
End Sub

Private Sub Winsock1_Close()
    Caption = "Client : disconnected ."
    IsConnectionOpen = False
End Sub

Private Sub Winsock1_Connect()
    Caption = "Client : connected ."
    IsConnectionOpen = True
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim str As String
    
    Winsock1.GetData str
    Text4.Text = Text4.Text + str '+ Chr(13) + Chr(10)
    Text4.SelStart = Len(Text4.Text)
End Sub

Private Sub Winsock1_Error(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)
    Winsock1.Close
    Number = 0
End Sub

⌨️ 快捷键说明

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