Contributions
Re: Error: Only one usage of each socket address (protocol/network address/port) is normally permitted
Alex What you siad might be true, Testcomplete got struck while executing the script and crashed. May be the socket didn't get closed. Tried either ways but not able to fix the issue. Any othe ralternatives53KViews0likes0CommentsError: Only one usage of each socket address (protocol/network address/port) is normally permitted
Hi I am trying to conenct to the server through TCp/Ip protocolu using VB script: Sample code ref:http://support.smartbear.com/viewarticle/9004/ Can anyone help me in understanding the below error msg: System.Net.Sockets.SocketException (0x80004005): Only one usage of each socket address (protocol/network address/port) is normally permitted. Thanks, ReshmaSolved62KViews0likes5CommentsRe: How to write a TCP/IP client server socket program in vbscript?
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, Reshma21KViews2likes0Comments