Private Sub Form_Load()
myserver.LocalPort = 5211
myserver.bind
myserver.Listen
End Sub Private Sub myServer_ConnectionRequest(ByVal requestID As Long)
If myserver.State <> sckClosed Then
myserver.Close
End If
myserver.Accept requestID
End Sub Private Sub myServer_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
myserver.GetData strData
If strData = " hello " Then
MsgBox ("收到数据!")
End If
End Sub Private Sub myServer_Close()
myserver.Close
myserver.Listen
End Sub
在这个程序里,这几个函数中,除了Form_Load()会被运行外,其它函数都未被运行。我是在网上看到的这个教程,而且教程里还运行了这个程序,但我不知他是怎么运行的。没有条件去激活下面的几个函数啊?能说说吗?现在网上用这种例子说明winsock在VB里应用的很多教程都有类似的例子,怎么看下面几个函数都没有运行啊。
myserver.LocalPort = 5211
myserver.bind
myserver.Listen
End Sub Private Sub myServer_ConnectionRequest(ByVal requestID As Long)
If myserver.State <> sckClosed Then
myserver.Close
End If
myserver.Accept requestID
End Sub Private Sub myServer_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
myserver.GetData strData
If strData = " hello " Then
MsgBox ("收到数据!")
End If
End Sub Private Sub myServer_Close()
myserver.Close
myserver.Listen
End Sub
在这个程序里,这几个函数中,除了Form_Load()会被运行外,其它函数都未被运行。我是在网上看到的这个教程,而且教程里还运行了这个程序,但我不知他是怎么运行的。没有条件去激活下面的几个函数啊?能说说吗?现在网上用这种例子说明winsock在VB里应用的很多教程都有类似的例子,怎么看下面几个函数都没有运行啊。
Private Sub Form_Paint()
Private Sub Form_Resize()
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
这些
myserver.Listen 开始后,myserver就运作起来,并监听端口,如果有消息就响应
Private Sub myServer_ConnectionRequest(ByVal requestID As Long) '看字面理解,是新的连接事件
Private Sub myServer_DataArrival(ByVal bytesTotal As Long) '看字面理解,是数据到达事件
Private Sub myServer_Close() '看字面理解,是myServer关闭事件
就如同,窗口建立起来后,你鼠标点点,响应下面的函数,不用你直接调用的
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
你的想法和我的差不多,但我调试过程序,这个程序还有一半是
Private Sub form_Load()
myClient.RemoteHost = "127.0.0.1"
myClient.RemotePort = 5211
End Sub
Private sub cmdConnect_Click()
myClient.Connect
End sub Private Sub cmdsenddata_Click()
myClient.SendData "hello"
End Sub Private Sub myClient_Connect()
debug.print "success!"
end sub
两个程序一块调试也不成功。
2、新建程序B,上面放个winsock名字改为myClient;再放2个按钮名字分别改成cmdConnect和cmdsenddata; 再把四楼代码贴进去并运行
3、依次点程序B的两个按钮,肯定OK注意名字最好从代码中复制,以免出错!
我就是按你说的这个方法做的。但还是不行,先在窗口中建控件winsock1然后根据程序中的名称把控件名称改过来。msdn开始就看了。但不明白才问的。