VB中 winsock 无法连接上
服务器端代码如下:PrivateSubCommand1_Click()Winsock1.CloseWinsock1.LocalPort=200Winsock1.Remot...
服务器端代码如下:
Private Sub Command1_Click()
Winsock1.Close
Winsock1.LocalPort = 200
Winsock1.RemoteHost = 100
Winsock1.Listen
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim msg$
Winsock1.GetData msg
Print msg
Winsock1.Close
Winsock1.Listen
End Sub
客户端代码如下:
Private Sub Command1_Click()
Winsock1.LocalPort = 100
Winsock1.RemoteHost = "192.168.1.5"
Winsock1.RemotePort = 200
Winsock1.Connect
If Winsock1.State = 7 Then
Winsock1.SendData "fuck1"
Print "send message"
Winsock1.Close
End If
End Sub
服务端启动后,正常处于监听状态,客户端启动后,winsock.state 一直是6 ,无法连接。
服务器端和客户端都在本机运行,我也试过在局域网中的不同机器运行,效果都是客户端无法连接到服务端,这是为什么啊??
请高手赐教 展开
Private Sub Command1_Click()
Winsock1.Close
Winsock1.LocalPort = 200
Winsock1.RemoteHost = 100
Winsock1.Listen
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim msg$
Winsock1.GetData msg
Print msg
Winsock1.Close
Winsock1.Listen
End Sub
客户端代码如下:
Private Sub Command1_Click()
Winsock1.LocalPort = 100
Winsock1.RemoteHost = "192.168.1.5"
Winsock1.RemotePort = 200
Winsock1.Connect
If Winsock1.State = 7 Then
Winsock1.SendData "fuck1"
Print "send message"
Winsock1.Close
End If
End Sub
服务端启动后,正常处于监听状态,客户端启动后,winsock.state 一直是6 ,无法连接。
服务器端和客户端都在本机运行,我也试过在局域网中的不同机器运行,效果都是客户端无法连接到服务端,这是为什么啊??
请高手赐教 展开
展开全部
码如下:
Private Sub Command1_Click()
Winsock1.LocalPort = 200
Winsock1.Listen
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim msg$
Winsock1.GetData msg
Print msg
End Sub
客户端代码如下:
Private Sub Command1_Click()
Winsock1.LocalPort = 100
Winsock1.RemoteHost = "192.168.1.5"
Winsock1.Connect
If Winsock1.State = 7 Then
Winsock1.SendData "fuck1"
Print "send message"
End If
End Sub
这样就可以了!!
Private Sub Command1_Click()
Winsock1.LocalPort = 200
Winsock1.Listen
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim msg$
Winsock1.GetData msg
Print msg
End Sub
客户端代码如下:
Private Sub Command1_Click()
Winsock1.LocalPort = 100
Winsock1.RemoteHost = "192.168.1.5"
Winsock1.Connect
If Winsock1.State = 7 Then
Winsock1.SendData "fuck1"
Print "send message"
End If
End Sub
这样就可以了!!
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
是做TCP吗?接受端好像不是直接收数据的,好像是WINSOCK1用收到连接的事件里将连接再送给另一个WINSOCK,也就是服务器端要建两个WINSOCK,收发数据时用新的WINSOCK和客户端发
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
服务端:
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
me.Caption = "连接成功"
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
Winsock1.Close
Winsock1.Accept requestID
me.Caption = "连接成功"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询