vb中winsock控件 TCP无法连接 100

客户:PrivateSubForm_Load()Me.ShowfrmServer.ShowtcpCilent.RemotePort=14310tcpCilent.Remo... 客户:
Private Sub Form_Load()
Me.Show
frmServer.Show
tcpCilent.RemotePort = 14310
tcpCilent.RemoteHost = "192.168.1.100"
txtMassage.Visible = False
lblState = "未连接服务器"
End Sub
Private Sub cmdConnect_Click()
On Error Resume Next
tcpCilent.Connect
lblState = "连接中..."
MsgBox "已经开始连接!", vbInformation
If tcpCilent.State <> sckConnected Then lblState = "连接出错": MsgBox "未找到服务器!", vbCritical
End Sub
Private Sub tcpCilent_Connect()
cmdConnect.Enabled = False
cmdSend.Default = True
cmdSend.Enabled = True
txtMassage.Visible = True
MsgBox "连接成功!"
End Sub
服务器:
Private Sub Form_Load()
Me.Show
tcpServer.LocalPort = 14310
tcpServer.Listen
MsgBox "已经开始监听,等待客户上线!", vbInformation
fstClosed = True
cmdSend.Enabled = False
cmdShutdown.Enabled = False
End Sub
Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
If tcpServer.State <> sckClosed Then tcpServer.Close
tcpServer.Accept requestID
If tcpServer.State = sckConnected Then
MsgBox "客户已上线!", vbInformation
cmdSend.Enabled = True
cmdShutdown.Enabled = True
tcpServer.SendData "服务器连接成功!"
Else
MsgBox "客户连接错误!", vbCritical
End If
End Sub
Private Sub tcpServer_Close()
If fstClosed Then
If MsgBox("客户已下线,是否退出?", vbYesNo + vbExclamation) = vbYes Then End
End If
fstClosed = False
End Sub
请问为什么不能达到连接的效果?
展开
 我来答
年华似水118
2013-05-18 · TA获得超过145个赞
知道答主
回答量:112
采纳率:0%
帮助的人:51.8万
展开全部
tcpCilent_Connect()后没有socket发送数据。
更多追问追答
追问
怎样Socket发送数据?
追答
客户端:
Private Sub Form_Load()
serverIP = "192.168.1.100"
If WS_tcpCilent.State 0 Then WS_ tcpCilent.Close
Ws_tcpCilent.connect serverIP ,14310
End Sub
Private Ws_tcpCilent_connect ()
MSgbox "连接成功"
End sub
Private Ws_tcpCilent_DataArrival(ByVal bytesTotal As Long)
MSgbox "服务器有数据回来了"
End sub
Private Sub cmdConnect_Click()
cmdConnect.Enabled = False
cmdSend.Default = True
cmdSend.Enabled = True
txtMassage.Visible = True
Ws_tcpCilent.SendData "测试"
End Sub
服务器端
Private Sub Form_Load()
//不用修改
End Sub
Private Sub tcpServer_ConnectionRequest(ByVal requestID As Long)
//?至于搞这么复杂吗,这个事件是已经连接上的事件,直接MSGBOX就可以了
End Sub
Private Sub tcpServer_Close()
//??你这close事件谁触发的?客户端没见触发close事件啊,这段代码没用吧
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式