vb winsock控件实时错误40006 求助
server:PrivateSubForm_Load()DimPortAsIntegerPort=InputBox("IP(Frm1)","","2008")Winsoc...
server:
Private Sub Form_Load()
Dim Port As Integer
Port = InputBox("IP(Frm1)", "", "2008")
Winsock1.RemotePort = Port
Winsock1.Listen
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1 <> 0 Then: Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DData As String
Winsock1.GetData DData
Text1 = DData
End Sub
Client:
Private Sub Command1_Click()
Winsock1.Connect
End Sub
Private Sub Form_Load()
Dim IP As String
Dim Port As Integer
IP = InputBox("IP(Frm2)", "", "127.0.0.1")
Port = InputBox("Port", "", "2008")
Winsock1.RemoteHost = IP
Winsock1.RemotePort = Port
End Sub
Private Sub Text1_Change()
Winsock1.SendData Text1
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
经测试:服务端(Frm1.winsock1.state=2)
客户端(Frm1.winsock1.state=9)
孤星逐梦
我SERVER那边的winsock1.listen
还有过程Winsock1_ConnectionRequest里的意思是如果客户连接时没关闭连接, _
那么关闭连接,这样有错吗?
如果改的话应该怎么改?谢谢 展开
Private Sub Form_Load()
Dim Port As Integer
Port = InputBox("IP(Frm1)", "", "2008")
Winsock1.RemotePort = Port
Winsock1.Listen
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1 <> 0 Then: Winsock1.Close
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DData As String
Winsock1.GetData DData
Text1 = DData
End Sub
Client:
Private Sub Command1_Click()
Winsock1.Connect
End Sub
Private Sub Form_Load()
Dim IP As String
Dim Port As Integer
IP = InputBox("IP(Frm2)", "", "127.0.0.1")
Port = InputBox("Port", "", "2008")
Winsock1.RemoteHost = IP
Winsock1.RemotePort = Port
End Sub
Private Sub Text1_Change()
Winsock1.SendData Text1
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
经测试:服务端(Frm1.winsock1.state=2)
客户端(Frm1.winsock1.state=9)
孤星逐梦
我SERVER那边的winsock1.listen
还有过程Winsock1_ConnectionRequest里的意思是如果客户连接时没关闭连接, _
那么关闭连接,这样有错吗?
如果改的话应该怎么改?谢谢 展开
1个回答
展开全部
Client:
Private Sub Command1_Click()
Winsock1.Connect
End Sub
Private Sub Form_Load()
Form2.Show
Dim IP As String
Dim Port As Integer
IP = InputBox("IP(Frm2)", "", "127.0.0.1")
Port = InputBox("Port", "", "2008")
Winsock1.RemoteHost = IP
Winsock1.RemotePort = Port
End Sub
Private Sub Text1_Change()
Winsock1.SendData Text1
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
server:
Private Sub Form_Load()
Dim Port As Integer
Port = InputBox("IP(Frm1)", "", "2008")
Winsock1.LocalPort = Port '''这里是监听而不是连接
Winsock1.Listen
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then: Winsock1.Close '''这里要写状态的
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DData As String
Winsock1.GetData DData
Text1 = DData
End Sub
Private Sub Command1_Click()
Winsock1.Connect
End Sub
Private Sub Form_Load()
Form2.Show
Dim IP As String
Dim Port As Integer
IP = InputBox("IP(Frm2)", "", "127.0.0.1")
Port = InputBox("Port", "", "2008")
Winsock1.RemoteHost = IP
Winsock1.RemotePort = Port
End Sub
Private Sub Text1_Change()
Winsock1.SendData Text1
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
server:
Private Sub Form_Load()
Dim Port As Integer
Port = InputBox("IP(Frm1)", "", "2008")
Winsock1.LocalPort = Port '''这里是监听而不是连接
Winsock1.Listen
End Sub
Private Sub Timer1_Timer()
Label1 = Winsock1.State
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then: Winsock1.Close '''这里要写状态的
Winsock1.Accept requestID
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim DData As String
Winsock1.GetData DData
Text1 = DData
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询