VB6 winsock.ocx bug? 
Author Message
 VB6 winsock.ocx bug?

I am a winsock newbie. I wrote a little tcp program by vb6 as followes:

frmServer.frm
--------
private sub command1_click()
  scktcpServer.localport=1007
  scktcpServer.listen
end sub

private sub scktcpServer.ConnectionRequest(Byval requestID as Long)
(nothing)--->that means no sockets accpet request
end sub
=======================

frmClient.frm
----------
private sub command1_click()
  scktcpClient.remotehost="127.0.0.1"
  scktcpClient.remoteport=1007
  scktcpClient.connect
end sub

I run them. But what's strange is that I alaways got a
scktcpClient.Connect() event though I didn't accept any request in Server

The book I read says that
"The Client socket will receive a connect event only after server scokets
accpet it"

What's wrong?

Anyone can give me some hints? or show me how to make client know if it is
accepted or rejected.

Thanks a lot,

-----
kevin



Tue, 03 Jul 2001 03:00:00 GMT  
 VB6 winsock.ocx bug?
Hi...I am here again. :)

After posting the last message, I found I could handle that by as followes:
I think the connect event occurs evertime the client finds server listen on
the port and ask to connect it.

The book I have may be wrong. :)

In server
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Dim ans As Long
    Winsock1.Close
    Winsock1.Accept requestID
    Label1.Caption = "Checking"
    ans = MsgBox("Yes or No?", vbYesNo)

    If ans = vbYes Then
        Winsock1.SendData "CONNECTED"
    Else
        Winsock1.SendData "REJECT"
    End If
End Sub

In Client
Private Sub Command1_Click()
    Winsock1.Close
    Winsock1.RemoteHost = "127.0.0.1"
    Winsock1.RemotePort = 1007
    Winsock1.Connect

    Do
        DoEvents
    Loop Until Winsock1.State = sckConnected Or _
                   Winsock1.State = sckError
    If Winsock1.State = sckError Then
        MsgBox "Unable to connect to host."
    End If
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim DataReceived As String

    Winsock1.GetData DataReceived, vbString
    Select Case DataReceived
        Case "REJECT"
            MsgBox "Reject your call"
            Winsock1.SendData "QUIT"
        Case "CONNECTED"
            MsgBox "Connecting succeeded"
    End Select
End Sub



Tue, 03 Jul 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Microsoft Winsock OCX bugs

2. VB5 Winsock OCX Bug?

3. winsock ocx bug?

4. GRID32.OCX bugs on VB6

5. VB6 and Winsock(.ocx)

6. Automation Error with Winsock OCX on NT 4 -- compiled with VB6 (SP5)

7. Winsock/MSWINSCK.OCX/VB6

8. Winsock.OCX VB5 & VB6 Problem

9. VB6 MSWinSck.ocx Winsock.State=sckClosing

10. Automation Error with Winsock OCX on NT 4 -- compiled with VB6 (SP5)

11. How can I get the IP-Adress with VB6 without winsock.ocx

12. Winsock OCX vs Winsock API?

 

 
Powered by phpBB® Forum Software