Results 1 to 12 of 12

Thread: [VB6] Winsock, and sending amounts of bytes

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    56

    [VB6] Winsock, and sending amounts of bytes

    Ok, here's what im trying to accomplish. There's a text box. There's a button. There's a winsock control. The user types in an amount of bytes into the text box. (Like in CMD, with the 'ping' function. Nothing special, just raw bytes) The user presses the button, and with amount of raw bytes are sent to the remote host via winsock. Ive tried converting string to bytes, but that just sends the amount of bytes in that string. Not the integer amount. Any ideas? Thanks.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [VB6] Winsock, and sending amounts of bytes

    Not quite sure I understand, do you just want to send the number of characters the user typed into the TextBox ? If so then
    Code:
    Winsock1.SendData Len(Text1.Text)

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    56

    Re: [VB6] Winsock, and sending amounts of bytes

    What I mean was, If I type 32 into the textboxy, it will send 32 bytes, not the amount of bytes in the string "32".

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [VB6] Winsock, and sending amounts of bytes

    32 bytes of what ?
    Code:
    Dim strData As String 
    Dim intCount As Integer
    Dim intI As Integer
    intCount = Val(Text1.Text)
    '
    ' Create some data intCount long
    '
    For intI = 1 To intCount
        strData = strData & Cstr(intI)
    Next intI
    Winsock1.SendData strData

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    56

    Re: [VB6] Winsock, and sending amounts of bytes

    raw data... Have you used ping in cmd? If not, try 'ping vbforums.com' in cmd.
    It just sends 32 raw bytes of data. That's all I need it to do lol.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [VB6] Winsock, and sending amounts of bytes

    Code:
    Private Sub cmdPing_Click()
    Dim strData As String
    Dim intI As Integer
    For intI = 48 To 48 + 32
        strData = strData & Chr(intI)
    Next intI
    Winsock1.SendData strData
    End Sub
    Will send 32 characters. (What do you mean by "raw data" ?) Ping sends characters

  7. #7

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    56

    Re: [VB6] Winsock, and sending amounts of bytes

    Is 1 character 1 byte? Sorry for being difficult lol.

  8. #8
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [VB6] Winsock, and sending amounts of bytes

    As far as Winsoick is concerned, yes

  9. #9

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    56

    Re: [VB6] Winsock, and sending amounts of bytes

    Code:
    Private Sub cmdPing_Click()
    Dim strData As String
    Dim intI As Integer
    For intI = 48 To 48 + Val(Text1.text)
        strData = strData & Chr(intI)
    Next intI
    Winsock1.SendData strData
    End Sub
    Would that do what I specified in my first post?
    Just making sure I understand.
    Nothing worse than adding something into your project that you don't understand.
    Person - "What does that do?"
    Me - "Uhhh" Lol.

  10. #10
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [VB6] Winsock, and sending amounts of bytes

    I'd tart it up a bit and put a few comments in to help with the understanding.
    Code:
    Private Sub cmdPing_Click()
    Dim strData As String
    Dim intI As Integer
    Dim intCount As Integer
    intCount = Val(Text1.Text)
    '
    ' Check for a valid number of characters to send
    '
    If intCount > 0 And intCount < 256 - 48 Then
        '
        ' Create a string of length equal to the
        ' number input by the user
        ' Starts with the Character "0" (AscII 48), then "1" etc
        ' up to the last value
        '
        For intI = 48 To 48 + Val(Text1.Text)
            strData = strData & Chr(intI)
        Next intI
        'Debug.Print strData    'Uncomment this to see
                                'the string displayed
                                'in the Immediate Window
        Winsock1.SendData strData
    Else
        MsgBox "Invalid Character Count"
    End If

  11. #11

    Thread Starter
    Member
    Join Date
    Feb 2008
    Posts
    56

    Re: [VB6] Winsock, and sending amounts of bytes

    Ok, thanks.

  12. #12
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: [VB6] Winsock, and sending amounts of bytes

    vb Code:
    1. Winsock1.SendData String$(Text1.Text, "A")

    If you typed 4 into the TextBox it would send "AAAA".

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