Results 1 to 12 of 12

Thread: WinSock Problems!

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    Unhappy

    I'm trying to send data between to computer using the WinSock Control! But it doesn't work!

    I'm trying to send the data in a textfield(SendData) to another computer on the network, but I get the following error:
    Run-Time error: 40006
    Wrong Protocol or connection state for the requested transaction or request.

    What's wrong here!?


    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Junior Member
    Join Date
    Feb 1999
    Posts
    25

    Exclamation

    The problem is that you're not connected to the computer you're trying to send data to. You can check this by typing this in before you send the data, Debug.Print (name of winsock control here).State. If it does not print 7, then you are not connected.

    Here is what all the state numbers mean:

    sckClosed 0 Default. Closed
    sckOpen 1 Open
    sckListening 2 Listening
    sckConnectionPending 3 Connection pending
    sckResolvingHost 4 Resolving host
    sckHostResolved 5 Host resolved
    sckConnecting 6 Connecting
    sckConnected 7 Connected
    sckClosing 8 Peer is closing the connection
    sckError 9 Error

  3. #3
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Accept requestID
    End Sub

  4. #4

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    The Winsock state is 0
    How can i make go 7???
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  5. #5
    Junior Member
    Join Date
    Feb 1999
    Posts
    25
    The Visual Basic help file shows you how to use the winsock control.

  6. #6
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111
    The winsock control you're going to connect to must be listening for it:
    Winsock1.Listen
    Make sure it's local port is that of the other winsocks remote port. And you have the address, all the required stuff. Then call:
    Winsock1.Connect
    Then in your winsock_connect function type something like:
    Form1.Caption = "Connected"
    Or:
    check if the state is 7 before you send stuff
    If winsock1.state <> 7 then exit sub
    'data here

  7. #7
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Add two buttons and two textboxes to 1 form, name one text box txtIP and the other txtData, next name one Button cmdSend and the other cmdConnect. Here is the code for the CLIENT::

    Private Sub cmdConnect_Click()
    Winsock1.Connect txtIP.Text, 1234
    End Sub

    Private Sub Winsock1_Connect()
    Me.Caption = "Connected"
    End Sub

    Private Sub cmdSend_Click()
    Winsock1.SendData txtData.Text
    End Sub

    For the server add a textbox to the form called txtData and a button call cmdListen. Here is the code for the SERVER::

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Accept requestID
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    Winsock1.GetData strData, vbString
    txtData.Text = strData
    End Sub

    Private Sub cmdListen_Click()
    Winsock1.LocalPort = 1234
    Winsock1.Listen
    End Sub

    This shoud do it for you to send data from one pc to another.

  8. #8

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    It still doesn't work....
    The winsock state is 6....it never goes 7
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  9. #9
    Guest
    It'd be better if you post your code (both server and client), that way we can find the problem rather than guess what it might be.

    Sunny

  10. #10
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    I'll send you a demo app if you give me your email address

  11. #11

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    my email:
    [email protected]
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  12. #12

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Client code

    Code:
    Private Sub cmdConnect_Click()
    Winsock1.Connect txtIP.Text, 1234
    
    
    Debug.Print Winsock1.State
    End Sub
    
    Private Sub cmdSend_Click()
    Winsock1.SendData txtData.Text
    End Sub
    
    Private Sub Winsock1_Connect()
    Me.Caption = "Connected"
    End Sub
    Server code:

    Code:
    Private Sub cmdListen_Click()
    Winsock1.LocalPort = 1234
    Winsock1.Listen
    
    End Sub
    
    Private Sub Form_Load()
    Winsock1.LocalPort = 1234
    Winsock1.Listen
    End Sub
    
    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Accept requestID
    Winsock1.Bind
    End Sub
    
    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim strData As String
    Winsock1.GetData strData, vbString
    txtData.Text = strData
    
    End Sub
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

Posting Permissions

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



Click Here to Expand Forum to Full Width