📄 form4.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form4
Caption = "Form4"
ClientHeight = 5940
ClientLeft = 60
ClientTop = 345
ClientWidth = 6420
LinkTopic = "Form4"
MaxButton = 0 'False
ScaleHeight = 5940
ScaleWidth = 6420
StartUpPosition = 3 '窗口缺省
Begin MSWinsockLib.Winsock Winsock1
Left = 6000
Top = 360
_ExtentX = 741
_ExtentY = 741
_Version = 393216
Protocol = 1
End
Begin VB.CommandButton Command2
Caption = "发送"
Height = 375
Left = 4920
TabIndex = 6
Top = 5520
Width = 735
End
Begin VB.Frame Frame2
Caption = "发送"
Height = 975
Left = 0
TabIndex = 4
Top = 4560
Width = 6135
Begin VB.TextBox Text5
Height = 615
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 5
Top = 240
Width = 5895
End
End
Begin VB.Frame Frame1
Caption = "聊天记录"
Height = 3615
Left = 0
TabIndex = 2
Top = 840
Width = 6135
Begin VB.TextBox Text4
Height = 3135
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 3
Top = 240
Width = 5895
End
End
Begin VB.TextBox Text2
Height = 270
Left = 4080
Locked = -1 'True
TabIndex = 1
Top = 360
Width = 1695
End
Begin VB.TextBox Text1
Height = 270
Left = 960
Locked = -1 'True
TabIndex = 0
Top = 360
Width = 1455
End
Begin VB.Label Label7
BackStyle = 0 'Transparent
Caption = "Label7"
Height = 255
Left = 4080
TabIndex = 12
Top = 0
Width = 1575
End
Begin VB.Label Label6
BackStyle = 0 'Transparent
Caption = "本机名:"
Height = 255
Left = 3360
TabIndex = 11
Top = 0
Width = 615
End
Begin VB.Label Label4
BackStyle = 0 'Transparent
Caption = "远程端口"
Height = 255
Left = 3000
TabIndex = 10
Top = 360
Width = 855
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "本机端口"
Height = 255
Left = 0
TabIndex = 9
Top = 360
Width = 735
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "Label2"
Height = 255
Left = 1200
TabIndex = 8
Top = 0
Width = 1695
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "本机IP地址"
Height = 255
Left = 0
TabIndex = 7
Top = 0
Width = 1095
End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command2_Click()
On Error GoTo ErrorPro
Dim s As String
s = xingming + Text5.Text
Winsock1.SendData s
Text4.Text = Text4.Text + Chr$(13) + Chr$(10) + "我说:" + Text5.Text
Text5.Text = ""
Exit Sub
ErrorPro:
MsgBox "网络出错,请重新连接!"
End
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Dim i As Integer
Dim j As Integer
Dim ss As String
Dim s1 As String
Dim s2 As String
Dim melocalport As String
Dim tlocalport As String
Label2.Caption = Winsock1.LocalIP
Label7.Caption = Winsock1.LocalHostName
'求本地端口
i = Len(Trim(Label2.Caption))
For j = i To j - 3 Step -1
ss = Mid(Trim(Label2.Caption), j, 1)
If ss <> "." Then
s1 = ss + s1
Else
Exit For
End If
Next j
melocalport = 1000 + Val(s1)
Text1.Text = Trim(Str(melocalport))
'求远程端口
i = Len(Trim(ipname))
For j = i To j - 3 Step -1
ss = Mid(Trim(ipname), j, 1)
If ss <> "." Then
s2 = ss + s2
Else
Exit For
End If
Next j
tlocalport = 1000 + Val(s2)
Text2.Text = Trim(Str(tlocalport))
Text4.Text = Left(Trim(xingming), Trim(Len(xingming) - 2)) + "-----" + "welcome!"
'联系
Winsock1.LocalPort = 2000
Winsock1.RemotePort = Text2.Text
On Error GoTo ErrorPro1
ErrorPro1:
Winsock1.RemoteHost = 2000
On Error GoTo ErrorPro2
Winsock1.RemoteHost = ipname
Winsock1.Bind 2000
form2k = True
Exit Sub
ErrorPro2:
Winsock1.RemoteHost = 20001
On Error GoTo ErrorPro3
Winsock1.RemoteHost = ipname
Winsock1.Bind 2001
form2k = True
Exit Sub
ErrorPro3:
Winsock1.RemoteHost = 20002
On Error GoTo ErrorPro4
Winsock1.RemoteHost = ipname
Winsock1.Bind 2002
form2k = True
Exit Sub
ErrorPro4:
Winsock1.RemoteHost = 20003
On Error GoTo ErrorPro2
Winsock1.RemoteHost = ipname
Winsock1.Bind 2003
form2k = True
Exit Sub
End Sub
Private Sub Form_Unload(Cancel As Integer)
form2k = False
End Sub
Private Sub Text5_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
On Error GoTo ErrorPro
Dim s As String
s = xingming + Text5.Text
Winsock1.SendData s
Text4.Text = Text4.Text + Chr$(13) + Chr$(10) + "我说:" + Text5.Text
Text5.Text = ""
Exit Sub
ErrorPro:
MsgBox "网络出错,请重新连接!"
End
End If
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
On Error GoTo ErrorPro
Dim receviedata As String
Winsock1.GetData receviedata
Text4.Text = Text4.Text + Chr$(13) + Chr$(10) + receviedata
Exit Sub
ErrorPro:
MsgBox "网络出错,请重新连接!"
End
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -