Forum Discussion
- julie_mcmanusOccasional ContributorThanks again, however this isn't exactly what I needed to do. I do however have something that works now.
maxLength = 2;
byteType = dotNET.System.Type.GetType("System.Byte");
binaryData = dotNET.System.Array.CreateInstance(byteType, maxLength);
binaryData.Set(1, 0xA);
The binaryData.Set() method works with the SendTo() method. - Philip_BairdCommunity Expert
- TanyaYatskovskaSmartBear Alumni (Retired)Hi Julie,
I guess you are working with the sample Phil's talking about. You need to uncomment these lines:
maxLength = 256;
byteType = dotNET.System.Type.GetType("System.Byte");
binaryData = dotNET.System.Array.CreateInstance(byteType, maxLength);
- julie_mcmanusOccasional Contributor
- Philip_BairdCommunity ExpertHi Julie, I reproduced the problem you are having, it appears Test Complete is not passing a byte to the SetValue() method.
I would expect the following to work as the code is doing an explicit cast to Byte using System.Convert.ToByte (ToByte_13 is the overload that accepts a String paramter).
var maxLength = 256;
var byteType = dotNET.System.Type.GetType("System.Byte");
var binaryData = dotNET.System.Array.CreateInstance(byteType, maxLength);
binaryData.SetValue( dotNET.System.Convert.ToByte_13( "1" ), 0 );
However, this gives the same type exception.
If you change dotNET.System.Type.GetType("System.Byte"); to dotNET.System.Type.GetType("System.Int32"); it works nicely.
Perhaps someone from SmartBear can provide further details.
Regards,
Phil Baird - TanyaYatskovskaSmartBear Alumni (Retired)Hi,
Do you want to use the SetValue method to set values of the array on a client side? I can suggest that you use the following approach to set the array of bytes from a string.
var binaryData = dotNET.System_Text.Encoding.ASCII.GetBytes_2("SomeMessage");
The approach with GetType("System.Byte") should work fine on the server side.
- julie_mcmanusOccasional ContributorThanks for the help with this, but still running into problems.
I need to send an array of bytes in hex format so for example I might want to send - 0x02 0x88 0x1e...
Tanya's solution converts each digit from a char so 02 sets the OleValue to 48,50 or hex 30,31 when what I need is simply 02 so I seem to have an issue with the types.
Phil's solution seems to indeed fill the array with the values I'm after but there are 2 issues -
I cannot enter alphanumeric such as "3a" otherwise I get an exception
if I enter just numbers such as "2", "12" etc. the array fills ok but at the next step where I call -
socket.SendTo(binaryData, endpoint); I get an exception, Invalid Proceedure call or argument. - TanyaYatskovskaSmartBear Alumni (Retired)Hi Julie,
Refer to this thread. It contains a function that converts the byte array to the HEX string. It may give you some clue what to do next.
- stapleshome7New ContributorHi Staff,
I am having some trouble with the TCP/IP server code published on your website. It fails on socket.bind. the error says :
Invalid procedure call or argument
address = "127.0.0.1";
port = 3751;
receiveTimeout = 15000;
connectionsQueueLength = 2;
socket = dotNET.System_Net_Sockets.Socket.zctor(
dotNET.System_Net_Sockets.AddressFamily.InterNetwork,
dotNET.System_Net_Sockets.SocketType.Stream,
dotNET.System_Net_Sockets.ProtocolType.Tcp
);
broadcast = dotNET.System_Net.IPAddress.Parse(address);
endpoint = dotNET.System_Net.IPEndPoint.zctor_2(broadcast, port);
socket.Bind(endpoint);
socket.Listen(connectionsQueueLength);
connectedSocket = socket.Accept();
connectedSocket.SetSocketOption_3(
dotNET.System_Net_Sockets.SocketOptionLevel.Socket,
dotNET.System_Net_Sockets.SocketOptionName.ReceiveTimeout,
receiveTimeout);
..................
Is there anything that I'm doing wrong?
Related Content
- 3 years ago
- 3 years ago
Recent Discussions
- 15 hours ago