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

📄 server.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         =   "Server :"
   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.CheckBox Check1 
      Caption         =   "CrLf"
      Height          =   300
      Left            =   2640
      TabIndex        =   6
      Top             =   720
      Width           =   855
   End
   Begin VB.TextBox Text3 
      Height          =   1935
      Left            =   240
      MultiLine       =   -1  'True
      TabIndex        =   5
      Text            =   "server.frx":0000
      Top             =   1200
      Width           =   4215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "Send"
      Height          =   375
      Left            =   3600
      TabIndex        =   4
      Top             =   720
      Width           =   855
   End
   Begin VB.TextBox Text2 
      Height          =   375
      Left            =   240
      TabIndex        =   3
      Top             =   720
      Width           =   2295
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1200
      TabIndex        =   1
      Text            =   "9000"
      Top             =   120
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Listen"
      Height          =   375
      Left            =   3120
      TabIndex        =   0
      Top             =   120
      Width           =   1335
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   120
      Top             =   480
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label Label1 
      Caption         =   "Port :"
      Height          =   255
      Left            =   240
      TabIndex        =   2
      Top             =   120
      Width           =   615
   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 err1
    Winsock1.LocalPort = CInt(Text1)
    Winsock1.Listen
    IsConnectionOpen = False
err1:
    'MsgBox Err.Description
End Sub

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

End Sub

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

Private Sub Winsock1_Close()
    Caption = "Server : The Client disconnected."
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.Accept requestID
    IsConnectionOpen = True
    Caption = "Server : The Client connected."

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim str As String
    
    Winsock1.GetData str
    Text3.Text = Text3.Text + str
    Text3.SelStart = Len(Text2.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)
    'MsgBox Description
    Number = 0
End Sub

⌨️ 快捷键说明

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