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

📄 frmserver.frm

📁 用VB控件WINSOCK的TCP协议制作的局域网聊天工具,做得不好
💻 FRM
字号:
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "RICHTX32.OCX"
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmServer 
   Caption         =   "tcpServer"
   ClientHeight    =   4275
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   5535
   BeginProperty Font 
      Name            =   "宋体"
      Size            =   12
      Charset         =   134
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   LinkTopic       =   "Form1"
   ScaleHeight     =   4275
   ScaleWidth      =   5535
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdClear 
      Caption         =   "清除"
      Height          =   495
      Left            =   1920
      TabIndex        =   6
      Top             =   3720
      Width           =   1335
   End
   Begin VB.TextBox txtOutput 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   9
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1935
      Left            =   2880
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   3
      Top             =   1560
      Width           =   2355
   End
   Begin MSWinsockLib.Winsock tcpServer 
      Left            =   3240
      Top             =   2040
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin RichTextLib.RichTextBox txtSend 
      Height          =   1935
      Left            =   0
      TabIndex        =   2
      Top             =   1560
      Width           =   2295
      _ExtentX        =   4048
      _ExtentY        =   3413
      _Version        =   393217
      Enabled         =   -1  'True
      TextRTF         =   $"frmServer.frx":0000
   End
   Begin VB.Label lblLocalPort 
      Caption         =   "服务器端口  "
      Height          =   495
      Left            =   2880
      TabIndex        =   5
      Top             =   360
      Width           =   2415
   End
   Begin VB.Label lblLocalIP 
      Caption         =   "服务器IP  "
      Height          =   495
      Left            =   0
      TabIndex        =   4
      Top             =   360
      Width           =   2775
   End
   Begin VB.Label lblOutput 
      Caption         =   "接收数据"
      Height          =   255
      Left            =   2880
      TabIndex        =   1
      Top             =   1080
      Width           =   975
   End
   Begin VB.Label lblSend 
      Caption         =   "发送数据"
      Height          =   255
      Left            =   0
      TabIndex        =   0
      Top             =   1080
      Width           =   975
   End
End
Attribute VB_Name = "frmServer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdClear_Click()
'清除发送窗口和接收窗口的内容
  txtSend.Text = ""
  txtOutput.Text = ""
End Sub

Private Sub cmdSend_Click()
'将发送窗口的数据发送给服务器
tcpServer.SendData txtSend.Text
End Sub

Private Sub Form_Load()
'显示服务器IP地址和所用端口号,以及让服务器侦听该端口号
  tcpServer.LocalPort = 1000
  tcpServer.Listen
  lblLocalIP.Caption = lblLocalIP.Caption + CStr(tcpServer.LocalIP)
  lblLocalPort.Caption = lblLocalPort.Caption + CStr(tcpServer.LocalPort)
End Sub

Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
'检查控件的State属性是否为关闭的,如不是,在接受新的连接之前先关闭此连接
  If tcpServer.State <> sckClosed Then tcpServer.Close
  tcpServer.Accept requestID
  
End Sub

Private Sub tcpServer_DataArrival(ByVal bytesTotal As Long)
'接收从客户端传来的数据,并显示在接收窗口
  Dim StrData As String
  tcpServer.GetData StrData
  txtOutput.Text = StrData
End Sub




Private Sub txtSend_Change()
'当发送窗口的数据有所改变时将改变的数据发送给服务器
  tcpServer.SendData txtSend.Text
End Sub

⌨️ 快捷键说明

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