Results 1 to 5 of 5

Thread: Winsock [RESOLVED]

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147

    Question Winsock [RESOLVED]

    I am trying to get to grips with winsock (I feel it is about time).

    I have create a client and put the connect, send and close commands behind different button click events and it works fine, but when i come to try to do it behind one click event no data is sent. I don’t get any errors but no data is sent to the server app.

    Any suggestions please.



    VB Code:
    1. Private Sub Command1_Click()
    2. Dim count As Integer
    3. Dim iData(1 To 4096) As Byte
    4. Dim J As Long
    5. Dim InputLength As Long
    6.  
    7. If winsock1.State <> sckClosed Then winsock1.Close
    8. winsock1.Connect
    9.  
    10. iData(1) = 1
    11. iData(2) = 4
    12. iData(3) = 0
    13. iData(4) = 4
    14. iData(5) = 0
    15. iData(6) = 2
    16. iData(7) = 48
    17. iData(8) = 10
    18.  
    19. Do Until winsock1.State = sckConnected
    20.     DoEvents: DoEvents: DoEvents: DoEvents
    21.     If winsock1.State = sckError Then
    22.         MsgBox "No connection"
    23.         Exit Sub
    24.     End If
    25. Loop
    26.  
    27. For J = 1 To 8
    28.     winsock1.SendData (iData(J))
    29. Next
    30.  
    31. winsock1.Close
    32. End Sub
    Last edited by mik706; Jun 18th, 2003 at 04:26 AM.
    Mik706

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147
    If anyone is interested i have solved the problem by putting a delay in after the send command:

    VB Code:
    1. Private Sub Command5_Click()
    2. Dim count As Integer
    3. Dim iData(1 To 4096) As Byte
    4. Dim J As Long
    5. Dim InputLength As Long
    6.  
    7. If winsock1.State <> sckClosed Then winsock1.Close
    8. winsock1.Connect
    9.  
    10. iData(1) = 1
    11. iData(2) = 4
    12. iData(3) = 0
    13. iData(4) = 4
    14. iData(5) = 0
    15. iData(6) = 2
    16. iData(7) = 48
    17. iData(8) = 10
    18.  
    19. Do Until winsock1.State = sckConnected
    20.     DoEvents: DoEvents: DoEvents: DoEvents
    21.     If winsock1.State = sckError Then
    22.         MsgBox "No Connection"
    23.         Exit Sub
    24.     End If
    25. Loop
    26.  
    27. For J = 1 To 8
    28.     winsock1.SendData (iData(J))
    29. Next
    30.  
    31. For count = 1 To 32000
    32.     DoEvents
    33. Next
    34.  
    35. winsock1.Close
    36. End Sub
    Mik706

  3. #3
    Addicted Member
    Join Date
    Dec 2002
    Location
    Malaysia
    Posts
    224
    mik,

    It would be neater if you use a timer to control it.


    all the best,
    leng wai

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2002
    Location
    UK
    Posts
    147
    I have done, i put the example up before i changed to using a timer.
    Mik706

  5. #5
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    If it were me, i would break it up a little more:

    VB Code:
    1. Option Explicit
    2.  
    3. Dim blnSendComplete As Boolean
    4. Dim blnSendDataOnConnect As Boolean ' This is here incase you connect for another reason
    5.  
    6. Private Sub Command5_Click()
    7. If Winsock1.State <> sckClosed Then Winsock1.Close
    8. blnSendDataOnConnect = True
    9. Winsock1.Connect
    10. End Sub
    11.  
    12. Private Function SendData()
    13. Dim count As Integer
    14. Dim iData(1 To 4096) As Byte
    15. Dim J As Long
    16. 'Dim InputLength As Long EDIT: why is this here?
    17.  
    18. iData(1) = 1
    19. iData(2) = 4
    20. iData(3) = 0
    21. iData(4) = 4
    22. iData(5) = 0
    23. iData(6) = 2
    24. iData(7) = 48
    25. iData(8) = 10
    26.  
    27. For J = 1 To 8
    28.     Winsock1.SendData (iData(J))
    29.     Do Until blnSendComplete
    30.         DoEvents
    31.     Loop
    32.     blnSendComplete = False
    33. Next
    34.  
    35. Winsock1.Close
    36. End Function
    37.  
    38. Private Sub Winsock1_Connect()
    39. If blnSendDataOnConnect = True Then
    40.     SendData
    41. End If
    42. End Sub
    43.  
    44. Private Sub Winsock1_SendComplete()
    45. blnSendComplete = True
    46. End Sub
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

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