hello I'm writing a program using winsock..whenever i try to send some data from the client i get the following error
"Run-time error '40006' Wrong protocol or connection state for the requesting transaction or request"
please help me in finding what's going wrong...my client code is given below

Private Sub cmdLogin_Click()
    Dim ip, port As String
    ip = "127.0.0.1"
    port = "5500"
    
    sockClient.RemoteHost = ip
    sockClient.RemotePort = port
    sockClient.Connect
    
    Dim temp As String
    temp = "HELLO WORLD"
    sockClient.SendData temp
End Sub

Recommended Answers

All 2 Replies

If you put a watch on the sockClient control when you execute, you'll notice that the State property is 6 (Connecting). You have to throw in a DoEvents statement so the Connect event can occur. After that, you should be good to go.

Here's the code:

Private Sub cmdLogin_Click()
Dim ip, port As String
ip = "127.0.0.1"
port = "5500"
Me.sockClient.RemoteHost = ip
Me.sockClient.RemotePort = port
Me.sockClient.Connect

DoEvents

Dim temp As String
temp = "HELLO WORLD"
Me.sockClient.SendData temp

End Sub

Hope this helps!

commented: agree +13

hey thank you for the reply..i'm able to get the program work now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.