Forum Discussion
5 Replies
Sort By
- reshma_bhNew Contributor
Function Test()
Dim address, port, receiveTimeout, socket, connectionsQueueLength, connectedSocket, broadcast, endpoint, byteType, binaryData, maxLength, receivedLength, byteStr, str
address = "122.188.113.56"
port = 3000
receiveTimeout = xxxx
connectionsQueueLength = 0
Set 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)
Set broadcast = dotNET.System_Net.IPAddress.Parse(address)
Set endpoint = dotNET.System_Net.IPEndPoint.zctor_2(broadcast, port)
socket.Bind(endpoint)
socket.Listen(connectionsQueueLength)
connectedSocket = socket.Accept()
Call connectedSocket.SetSocketOption_3(dotNET.System_Net_Sockets.SocketOptionLevel.Socket,dotNET.System_Net_Sockets.SocketOptionName.ReceiveTimeout,receiveTimeout)
maxLength = 256
byteType = dotNET.System.Type.GetType("System.Byte")
binaryData = dotNET.System.Array.CreateInstance(byteType, maxLength)
If connectedSocket.ReceiveFrom(binaryData, endpoint)Then
receivedLength = connectedSocket.ReceiveFrom(binaryData, endpoint)
Else
'// An exception occurs if no data is received
receivedLength = 0
End IF
byteStr = ByteArrayToHexString(binaryData, receivedLength, "0x")
str = dotNET.System_Text.ASCIIEncoding.get_ASCII().GetString(binaryData)
str.SetLength(receivedLength)
Log.Message (receivedLength + " bytes were received: " + byteStr +"String Value: " + str)
if (str = "TestMessage") Then
Log.Message "The received data is valid and a positive response will be sent"
binaryData = dotNET.System_Text.Encoding.ASCII.GetBytes_2("OK")
else
Log.Message "The received data is invalid,a negative response will be sent"
binaryData = dotNET.System_Text.Encoding.ASCII.GetBytes_2("OK")
End IF
connectedSocket.Close
socket.Close
End Function
Function ByteArrayToHexString(byteArray, byteCount, prefix)
Dim i, string
string = ""
i = 1
Do While i = (i < byteArray.Length) & (i < byteCount)
string = dotNET.System.String.Format(prefix + "{0:X} ", byteArray.Get(i))
return string
Loop
End Function
Thanks,
Reshma
- TanyaYatskovskaSmartBear Alumni (Retired)
Hi Manne,
TestComplete documentation is huge! Post here the link where you found an example in JScript so that everybody could see the example.
- RajibPradhanOccasional ContributorHi,
Javascript code for TCP/IP socket is here.
http://support.smartbear.com/viewarticle/9004/
http://support.smartbear.com/viewarticle/9003/
Thanks,
Rajib - TanyaYatskovskaSmartBear Alumni (Retired)
Hi,
Great! As far as I can see, the System and System.Net assemblies are used there. Calling them in VBScript and JScript is very similar. You only need to use the Set statement to get the result in VBScript. Other changes are related only to the language syntax. Does anybody want to translate the scripts? We can add VBScript samples to these How To articles and specify the author name :).
- TanyaYatskovskaSmartBear Alumni (Retired)
Hi Reshma,
Thanks for the VBScript sample! I'll pass it to the team who can update the How To article.
Related Content
- 13 years agojyothi_priya
Recent Discussions
- 4 minutes agoSubhraDas
- 13 hours agoJacobjacob44