• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

Visual Basic 6 Winsock - Run-time Error

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

Chris_F

Member
Joined
Jun 30, 2003
Location
Columbus, Ohio
I'm having trouble with Winsock in VB6.

Code

Code:
Win.SendData "block"

Error

Code:
Run-Time Error 40006 - Wrong protocol or connection state for the requested tranaction or request.

PS. I renamed Winsock as Win.
 
Last edited:
Without looking at the full source I'd have to say that you likely dont have an open connection. IF you could show the whole source I'd be more than happy to track down the problem for you.
 
mmmm VB my favorite. i didnt even know ocforums had a programming section :)

yeah as Krieger said.. you probably arnt connected. were you LISTENING or CONNECTING ?

make sure you have win.accept setup right if you are listening. make a msgbox or something under win_connect()
 
Ok, I'm still having trouble connecting and sending data with the Winsock control.

Here is the receiver. No problems here, it works fine.

Code:
Private Sub Form_Load()
Win.LocalPort = 4999
Win.Listen
End Sub

Private Sub Command1_Click()
Win.Close
Win.Listen
End Sub

Private Sub Win_ConnectionRequest(ByVal requestID As Long)
Win.Close
Win.Accept requestID
End Sub

Private Sub Win_DataArrival(ByVal bytesTotal As Long)
Dim Data As String
Win.GetData Data
Text1.Text = Data
End Sub

And here is the sender. It still wont work.

Code:
Private Sub Form_Load()
Win.RemotePort = 4999
Win.RemoteHost = [My IP Adress]
End Sub

Private Sub Command1_Click()
SendData
End Sub


Private Sub SendData()
Data$ = "hello"
On Error GoTo Err:
Win.Close
Win.Connect
Win.SendData Data$

Err:
Win.Close
End Sub

I've tryed lots of things but none of them worked.
 
Chris_F, can you upload your code or pm me and I'll give you my email address and I'll take a look at it. I have to compare it to another project I did.

Thanks.
 
Back