[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. :thumb:
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)
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".
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
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.
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
Re: [VB6] Winsock, and sending amounts of bytes
Is 1 character 1 byte? Sorry for being difficult lol.
Re: [VB6] Winsock, and sending amounts of bytes
As far as Winsoick is concerned, yes
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.
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
Re: [VB6] Winsock, and sending amounts of bytes
Re: [VB6] Winsock, and sending amounts of bytes
vb Code:
Winsock1.SendData String$(Text1.Text, "A")
If you typed 4 into the TextBox it would send "AAAA".