【VB开源代码栏目提醒】:网学会员鉴于大家对VB开源代码十分关注,论文会员在此为大家搜集整理了“frmChatB.frm”一文,供大家参考学习
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmChatB
Caption = "ChatB"
ClientHeight = 2175
ClientLeft = 60
ClientTop = 450
ClientWidth = 4455
LinkTopic = "Form1"
ScaleHeight = 2175
ScaleWidth = 4455
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox txtSend
Height = 375
Left = 1320
TabIndex = 2
Top = 360
Width = 2895
End
Begin VB.TextBox txtAccept
Height = 375
Left = 1320
TabIndex = 1
Top = 1080
Width = 2895
End
Begin VB.CommandButton cmdSend
Caption = "发送"
Height = 375
Left = 3240
TabIndex = 0
Top = 1680
Width = 855
End
Begin MSWinsockLib.Winsock udpChatB
Left = 360
Top = 1560
_ExtentX = 741
_ExtentY = 741
_Version = 393216
Protocol = 1
End
Begin
VB.Label Label1
Caption = "发送的信息"
Height = 255
Left = 240
TabIndex = 4
Top = 480
Width = 975
End
Begin VB.Label Label2
Caption = "接收的信息"
Height = 255
Left = 240
TabIndex = 3
Top = 1080
Width = 975
End
End
Attribute VB_Name = "frmChatB"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdSend_Click()
'发送文本
udpChatB.SendData txtSend.Text
End Sub
Private Sub Form_Load()
With udpChatB
'将 RemoteHost 的值改为本地
计算机的名字或者localhost
.RemoteHost = "localhost"
.RemotePort = 1002 '要连接的端口。
.Bind 1001 '绑定到本地的端口上。
End With
End Sub
Private Sub udpChatB_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
udpChatB.GetData strData '将接受到的数据保存到strData中
txtAccept.Text = strData '将数据显示在文本框中
End Sub