dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: Error 40006 wrong protocol or connection state....

Hybrid View

  1. #1
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,264

    Error 40006 wrong protocol or connection state....

    Hello guys! Yes it's me again....
    I'm using TCP
    I get this error in run time
    Both computers are "connected" by clicking the Connect button on each, but when it is about to send the data (txtSend_LostFocus), it gives me this error.
    Why?
    How can I fix this?

    Here is my code for the server
    Code:
    Private Sub Form_Load()
        tcpClient2.RemoteHost = "Cmdupreez"
        tcpClient2.RemotePort = 1001
    End Sub
    
    Private Sub cmdConnect_Click()
        tcpClient2.Connect
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    tcpClient2.Close
    End Sub
    
    Private Sub tcpClient2_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    MsgBox Number & Description
    End Sub
    
    Private Sub txtSend_LostFocus()
        tcpClient2.SendData txtSend.Text
    End Sub
    
    Private Sub tcpClient2_DataArrival _
    (ByVal bytesTotal As Long)
        Dim strData As String
        tcpClient2.GetData strData
        txtOutPut.Text = strData
    End Sub
    and here is the code for the client
    Code:
    Private Sub Form_Load()
        tcpClient.RemoteHost = "HANNES"
        tcpClient.RemotePort = 1001
    End Sub
    
    Private Sub cmdConnect_Click()
        tcpClient.Connect
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    tcpClient.Close
    End Sub
    
    Private Sub txtSend_LostFocus()
        tcpClient.SendData txtSend.Text
    End Sub
    
    Private Sub tcpClient_DataArrival _
    (ByVal bytesTotal As Long)
        Dim strData As String
        tcpClient.GetData strData
        txtOutPut.Text = strData
    End Sub
    Enjoy your day!
    Hannes

  2. #2
    Join Date
    Jun 2002
    Location
    Clane, Ireland
    Posts
    766
    I have a project running using WINSOCK, with differing results, on my computers at home it works fine, on the servers in work it keeps getting time out errors so I may not be the best person to help here.

    However, if I remember correctly the server should be listening for the client, you use the property winsock.listen.

    Then when the client does winsock.connect, it fires off the connection request in your server program.

    Unless you are using a UDP protocol, in which case both computers have to bind the connection. I don't have access to the code here, so can't give definite answers but I'm 99% certain about this.

    HTH
    JP

    Please remember to rate all postings.

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,264
    Hi! thanx for the reply!

    I've tried this as well
    Code:
    Private intMax As Long
    Private Sub Form_Load()
       intMax = 0
       tcpServer(0).LocalPort = 1001
       tcpServer(0).Listen
    End Sub
    
    Private Sub tcpServer_DataArrival _
    (Index As Integer, ByVal bytesTotal As Long)
        Dim strData As String
        tcpServer(intMax).GetData strData
        txtOutPut.Text = strData
    End Sub
    
    Private Sub tcpServer_ConnectionRequest _
    (Index As Integer, ByVal requestID As Long)
       If Index = 0 Then
          intMax = intMax + 1
          Load tcpServer(intMax)
          tcpServer(intMax).LocalPort = 0
          tcpServer(intMax).Accept requestID
       End If
    End Sub
    
    Private Sub txtSend_LostFocus()
        tcpServer(intMax).SendData txtSend.Text
    
    End Sub
    But still, I get the same error

  4. #4
    Join Date
    Jun 2002
    Location
    Clane, Ireland
    Posts
    766
    In the server program, connection event you need to accept the request.
    JP

    Please remember to rate all postings.

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104
    would that be what this line is for:

    tcpServer(intMax).Accept requestID


    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  6. #6
    Join Date
    Jun 2002
    Location
    Clane, Ireland
    Posts
    766

    Red face

    Emm yes sorry I missed that.

    Do you need to have the following property set for the inital socket (i.e. index 0):
    .Protocol = sckTCPProtocol

    What error are you getting?

    Is it possible that a). something else is using port 1001, or b). that it is blocked by a firewall.

    Have you any code in the socket error event, and if so what is that telling you?

    Which side is giving you the error: Client or Server?
    JP

    Please remember to rate all postings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)