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

📄 form2.frm

📁 采用VB的WINSOCK控件实现的聊天程序,适合处学者.
💻 FRM
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "Mswinsck.ocx"
Begin VB.Form Form1 
   Caption         =   "SckClient"
   ClientHeight    =   4995
   ClientLeft      =   3450
   ClientTop       =   2145
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   4995
   ScaleWidth      =   4680
   Begin VB.CommandButton cmdSand 
      Caption         =   "发  送"
      Height          =   495
      Left            =   3360
      TabIndex        =   8
      Top             =   4200
      Width           =   1215
   End
   Begin VB.CommandButton Command2 
      Caption         =   "断  开"
      Height          =   495
      Left            =   1800
      TabIndex        =   7
      Top             =   4200
      Width           =   1335
   End
   Begin VB.CommandButton Command1 
      Caption         =   "连  接"
      Height          =   495
      Left            =   240
      TabIndex        =   6
      Top             =   4200
      Width           =   1335
   End
   Begin VB.TextBox Text3 
      Height          =   1095
      Left            =   960
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   5
      Top             =   2880
      Width           =   3375
   End
   Begin VB.TextBox Text2 
      Height          =   1095
      Left            =   960
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   4
      Top             =   1200
      Width           =   3375
   End
   Begin VB.TextBox Text1 
      Height          =   375
      Left            =   1800
      TabIndex        =   3
      Text            =   "202.118.227.16"
      Top             =   240
      Width           =   1815
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   4080
      Top             =   120
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.Label Label3 
      Caption         =   "客户消息:"
      Height          =   255
      Left            =   120
      TabIndex        =   2
      Top             =   2520
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "服务器发送的信息:"
      Height          =   255
      Left            =   120
      TabIndex        =   1
      Top             =   720
      Width           =   1695
   End
   Begin VB.Label Label1 
      Caption         =   "服务器的地址:"
      Height          =   375
      Left            =   120
      TabIndex        =   0
      Top             =   240
      Width           =   1335
   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 Form_Load()
Winsock1.RemotePort = 900
End Sub

Private Sub Command1_Click()
If Winsock1.State <> sckClosed Then Winsock1.Close  '如果套接字未关闭,先关闭之

Winsock1.RemoteHost = Text1.Text  '确定服务器的主机名

'Winsock1.Bind  '绑定套接字属性

Winsock1.Connect  '向服务器发出连接请求

Command1.Enabled = False '使Command1不可用

Command2.Enabled = True  '现在可以使其断开
End Sub

Private Sub Command2_Click()
Command1.Enabled = True

Command2.Enabled = False

Winsock1.Close '关闭当前套接字

End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)

Dim str As String

Winsock1.GetData str, vbString  '按照字符串类型接收信息


Text2.Text = "-->" + str + Chr$(13) + Chr$(10) + Text2.Text '立即更新到Text2中

End Sub

Private Sub Winsock1_Connect() '在连接成功后弹出消息框

MsgBox "connected to server!"


End Sub



⌨️ 快捷键说明

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