Archived Forum Post

Index of archived forum posts

Question:

ActiveX socket.SendBytes

Apr 30 '17 at 09:07

Hi

You need to send 10 bytes of Hex (x00 x01 x02 x03 x04 x05 x06 x07 x08 x09) You can do this with ActiveX socket.SendBytes

Success = socket.SendBytes (&H0001020304)

Success = socket.SendBytes (&H000102030405) - error

If more than 4 bytes then an error


Accepted Answer

I'm guessing the error you are getting is an Overflow error?

Assuming this is VB6, you can't stuff more than 4 bytes into a hex value indicated by the &H prefix since it converts to a 32-bit long integer at the most.

You should use a byte array of the required size and populate with the values you need, then pass the array to SendBytes.


Answer

Thank you

And how to transfer an array in SendBytes?


Answer

Assuming VB6, you can do something like this:

Dim la_Bytes() As Byte
Dim l_NumberOfBytes As Long

l_NumberOfBytes = 6
Redim la_Bytes(l_NumberOfBytes - 1)

la_Bytes(0) = &H00
la_Bytes(1) = &H01
la_Bytes(2) = &H02
la_Bytes(3) = &H03
la_Bytes(4) = &H04
la_Bytes(5) = &H05

success = socket.SendBytes(la_Bytes)

Answer

I am writing for VBScript (Visual Basic Scripting).

I tried your way, it works, but it's transmitted 20 bytes and not 10 bytes A similar problem was discussed at http://www.chilkatforum.com/questions/7683/how-to-ensure-sendbytes-only-sends-one-byte-per-character

It was suggested to use SendString StringCharset = "windows-1252", but I get an error.


set socket = CreateObject("Chilkat_9_5_0.Socket")

success = socket.UnlockComponent("xxxxx") MsgBox socket.LastErrorText

socket.KeepSessionLog = 1 socket.SessionLogEncoding = "hex"

ssl = 0 maxWaitMillisec = 20000 port = 80 success = socket.Connect("127.0.0.1",port,ssl,maxWaitMillisec)

MsgBox "Connect: " & success

dim new_arr(10)

new_arr(0) = &H00

new_arr(1) = &H01

new_arr(2) = &H02

new_arr(3) = &H03

new_arr(4) = &H04

new_arr(5) = &H05

new_arr(6) = &H06

new_arr(7) = &H07

new_arr(8) = &H08

new_arr(9) = &H09

success = socket.SendBytes(new_arr)

MsgBox socket.SessionLog


Answer

Try this:

Dim b(1 To 10) As Byte

b(1) = 0 b(2) = 1 b(3) = 2 b(4) = 3 b(5) = 4 b(6) = 5 b(7) = 6 b(8) = 7 b(9) = 8 b(10) = 9 success = socket.SendBytes(b)