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

📄 form1.frm

📁 采用VB的WINSOCK控件实现的聊天程序,适合处学者.
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "Mswinsck.ocx"
Begin VB.Form Form1 
   Caption         =   "SockSrv"
   ClientHeight    =   4020
   ClientLeft      =   3690
   ClientTop       =   2370
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   4020
   ScaleWidth      =   4680
   Begin VB.CommandButton cmdSand 
      Caption         =   "发   送"
      Height          =   375
      Left            =   2880
      TabIndex        =   7
      Top             =   3360
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "监     听"
      Height          =   375
      Left            =   1200
      TabIndex        =   6
      Top             =   3360
      Width           =   1335
   End
   Begin VB.TextBox Text3 
      Height          =   735
      Left            =   1440
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   5
      Top             =   2280
      Width           =   2895
   End
   Begin VB.TextBox Text2 
      Height          =   735
      Left            =   1440
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   4
      Top             =   1200
      Width           =   2895
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1440
      TabIndex        =   0
      Text            =   "900"
      Top             =   480
      Width           =   1215
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   3600
      Top             =   360
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label Label3 
      Caption         =   "服务器消息:"
      Height          =   255
      Left            =   240
      TabIndex        =   3
      Top             =   2280
      Width           =   1215
   End
   Begin VB.Label Label2 
      Caption         =   "客户消息:"
      Height          =   255
      Left            =   360
      TabIndex        =   2
      Top             =   1200
      Width           =   1095
   End
   Begin VB.Label Label1 
      Caption         =   "监听端口"
      Height          =   255
      Left            =   360
      TabIndex        =   1
      Top             =   600
      Width           =   975
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub cmdSand_Click()
If Winsock1.State = sckConnected Then Winsock1.SendData Text3.Text
End Sub

Private Sub Command1_Click()
If Winsock1.State <> sckClosed Then Winsock1.Close '在当前套接字未关闭时将其关闭

Winsock1.Bind    '将设置值生效

Winsock1.Listen  '监听端口的连接请求

End Sub

Private Sub Form_Load()
Winsock1.LocalPort = Text1.Text
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)

If Winsock1.State <> sckClosed Then Winsock1.Close

Winsock1.Accept requestID  '在监听的端口有连接请求发生时,立即调用Accept方法

'认可连接,使之生效。

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim strData As String

Winsock1.GetData strData, vbString '当有数据到达时,调用GetData方法接收之

Text2.Text = "-->" + strData + Chr$(13) + Chr$(10) + Text2.Text '将接收的内容更新显示在Text2中

End Sub

⌨️ 快捷键说明

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