【VB开源代码栏目提醒】:网学会员--在 VB开源代码编辑为广大网友搜集整理了:frmClientM.frm绩等信息,祝愿广大网友取得需要的信息,参考学习。
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form frmClientM
Caption = "TCP客户端"
ClientHeight = 3135
ClientLeft = 60
ClientTop = 450
ClientWidth = 4215
LinkTopic = "Form1"
ScaleHeight = 3135
ScaleWidth = 4215
StartUpPosition = 3 '窗口缺省
Begin MSWinsockLib.Winsock wskClient
Left = 240
Top = 3000
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.TextBox txtAccept
Height = 1575
Left = 240
MultiLine = -1 'True
ScrollBars = 3 'Both
TabIndex = 5
Top = 1320
Width = 3735
End
Begin VB.CommandButton cmdConnect
Caption = "连接"
Height = 375
Left = 3120
TabIndex = 3
Top = 840
Width = 855
End
Begin VB.CommandButton cmdSend
Caption = "发送"
Height = 375
Left = 1800
TabIndex = 2
Top = 840
Width = 855
End
Begin VB.TextBox txtSendData
Height = 375
Left = 1440
TabIndex = 1
Top = 240
Width = 2535
End
Begin
VB.Label Label3
Caption = "接收的消息:"
Height = 255
Left = 240
TabIndex = 4
Top = 960
Width = 1095
End
Begin VB.Label Label2
Caption = "发送的消息:"
Height = 255
Left = 240
TabIndex = 0
Top = 360
Width = 1095
End
End
Attribute VB_Name = "frmClientM"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdConnect_Click()
wskClient.RemoteHost = "localhost" '设置远程服务器地址
wskClient.RemotePort = 1002 '设置远程服务器端口号
wskClient.Connect '调用Connect函数连接服务器
End Sub
Private Sub cmdSend_Click()
If txtSendData.Text = "" Then '然后必须输入要发送的信息
MsgBox "请输入要发送的信息!!"
Exit Sub
End If
'调用Winsock的SendData方法发送信息
wskClient.SendData Caption + ":" + txtSendData.Text
End Sub
Private Sub wskClient_DataArrival(ByVal bytesTotal As Long)
Dim myData As String
wskClient.GetData myData '获取数据,保存到myData中
txtAccept.Text = txtAccept.Text + myData + vbCrLf '将数据显示到文本框中
End Sub
Private Sub wskClient_Error(ByVal Number As Integer, _
Description As String, ByVal Scode As Long, _
ByVal Source As String, ByVal HelpFile As String, _
ByVal HelpContext As Long, CancelDisplay As Boolean)
wskClient.Close
End Sub