VB中WinSock控件的问题

我的代码是这样的:PrivateSubcmdConnect_Click()winsock1.ConnectendSubPrivateSubform1_load()wins... 我的代码是这样的:
Private Sub cmdConnect_Click()
winsock1.Connect
end Sub
Private Sub form1_load()
winsock1.RemoteHost=127.0.0.1
winsock1.remoteport=5211
end sub
Private Sub winsock1Connect()
MsgBox "连接成功!"
End Sub
我是连接到本自己的计算机上的
但是当我点击按钮的时候竟然什么反映都没有
再点就出错了
请各位帮下忙
我已经知道不是代码的问题了,因为我发到群里的,他们那边是没问题的,但是我自己又用不了,我根据MDSN里提供的程序来做也不行,如果能帮我把这个问题解决掉就更好了
展开
 我来答
无涯海天
2010-07-30
知道答主
回答量:2
采纳率:0%
帮助的人:0
展开全部
winsock1.RemoteHost="127.0.0.1" 或者是winsock1.RemoteHost=localhost"
记得加引号就是了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友1b92564
2010-07-30
知道答主
回答量:29
采纳率:0%
帮助的人:11.8万
展开全部
Winsock通讯应该有2个程序来完成,你留个信箱,我明天发给你个例子
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
earnmoney08
2010-07-30 · TA获得超过316个赞
知道小有建树答主
回答量:607
采纳率:0%
帮助的人:305万
展开全部
我给你一个例子吧
不能发附件郁闷

Client:

Private Sub Form_Load()
Me.Caption = "Client-" & WinsockClient.LocalHostName & "-" & WinsockClient.LocalIP
TxtIP.Text = WinsockClient.LocalIP
If WinsockClient.State <> sckClosed Then WinsockClient.Close
WinsockClient.RemoteHost = Trim(TxtIP.Text)
WinsockClient.RemotePort = Val(TxtPort.Text)
WinsockClient.Connect
Debug.Print WinsockClient.State
TimerSendTimeCount.Interval = 2000
TimerSendTimeCount.Enabled = True
End Sub

Private Sub TimerSendTimeCount_Timer()
If WinsockClient.State = sckConnected Then
WinsockClient.SendData ("Client is ok!")
Debug.Print WinsockClient.State
Exit Sub
End If
If WinsockClient.State <> sckClosed And WinsockClient.State <> 6 Then WinsockClient.Close
WinsockClient.RemoteHost = Trim(TxtIP.Text)
WinsockClient.RemotePort = Val(TxtPort.Text)
WinsockClient.Connect
End Sub

Private Sub WinsockClient_DataArrival(ByVal bytesTotal As Long)
Dim Str As String
WinsockClient.GetData Str
Debug.Print Str
End Sub

Private Sub WinsockClient_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)
If TimerSendTimeCount.Enabled = False Then
TimerSendTimeCount.Interval = 2000
TimerSendTimeCount.Enabled = True
End If
End Sub

Host:

Private Sub Form_Load()
Me.Caption = "Host-" & WinsockHost.LocalHostName & "-" & WinsockHost.LocalIP
If WinsockHost.State <> sckClosed Then WinsockHost.Close
WinsockHost.LocalPort = Val(Me.TxtPort)
WinsockHost.Listen
End Sub

Private Sub WinsockHost_Close()
If WinsockHost.State <> sckClosed Then WinsockHost.Close
WinsockHost.LocalPort = Val(Me.TxtPort)
WinsockHost.Listen
End Sub

Private Sub WinsockHost_ConnectionRequest(ByVal requestID As Long)
If WinsockHost.State <> sckClosed Then WinsockHost.Close
WinsockHost.Accept requestID
End Sub

Private Sub WinsockHost_DataArrival(ByVal bytesTotal As Long)
Dim Str As String
Static n As Long
n = n + 1
If WinsockHost.BytesReceived = Len("Client is ok!") Then
WinsockHost.GetData Str, vbString, 13
TxtGetData.Text = TxtGetData.Text & Str & " " & n & vbCrLf
WinsockHost.SendData ("Host is ok! " & n)
End If
End Sub

Private Sub WinsockHost_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)
If WinsockHost.State <> sckClosed Then WinsockHost.Close
WinsockHost.LocalPort = Val(Me.TxtPort)
WinsockHost.Listen
End Sub

具体放那些控件你自己根据程序自己看着办吧呵呵
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式