📄 form1.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form1
Caption = "被动方"
ClientHeight = 4395
ClientLeft = 60
ClientTop = 345
ClientWidth = 5040
LinkTopic = "Form1"
ScaleHeight = 4395
ScaleWidth = 5040
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command1
Caption = "发送"
Default = -1 'True
Height = 375
Left = 3360
TabIndex = 2
Top = 3960
Width = 1215
End
Begin VB.TextBox Text2
Height = 975
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 0
Top = 2880
Width = 5055
End
Begin VB.TextBox Text1
Height = 2775
Left = 0
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 1
Top = 0
Width = 5055
End
Begin MSWinsockLib.Winsock connection
Left = 120
Top = 3960
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin MSWinsockLib.Winsock Winsock1
Left = 720
Top = 3960
_ExtentX = 741
_ExtentY = 741
_Version = 393216
LocalPort = 9000
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim lf As String
lf = Chr(13) & Chr(10)
If Text2.Text <> "" Then
'SendData方法,向对方发送数据。
connection.SendData Text2.Text
Text1.Text = Text1.Text & "我说:" & Now & lf & Text2.Text & lf
Text2.Text = ""
End If
End Sub
Private Sub connection_Close()
'Close方法,关闭和对方的连接。
connection.Close
End Sub
Private Sub connection_DataArrival(ByVal bytesTotal As Long)
Dim data As String
Dim lf As String
lf = Chr(13) & Chr(10)
'GetData访求,接收对方发过来的数据。参数vbString表示要接收字符串数据。
connection.GetData data, vbString
Text1.Text = Text1.Text & "对方说:" & Now & lf & data & lf
End Sub
Private Sub Form_Load()
'Bind和Listen方法,使服务器处理等待连接的状态。
Winsock1.Bind
Winsock1.Listen
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If connection.State = sckClosed Then
'Accept方法,接受一个连接。
connection.Accept requestID
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -