Dart Home | PowerTCP Telnet for .NET | Custom Development | Reply | PowerTCP Telnet for .NET Topics | Forums |
Author | Forum: PowerTCP Telnet for .NET Topic: ReadtoCount example |
creatinggenius From: Saratoga Springs, NY USA Posts: 10 Member Since: 08/29/11 |
posted September 12, 2011 12:13 PM can you please give me a ReadToCount sample in VB.net. My goal is to wait 30 seconds and gather all the text that the telnet server sends out. So I do not want to use ReadToDelimiter. So my code looks something like this TelnetControl.SocketOption.ReceiveTimeout = "30000" ' TelnetControl.Socket.ReceiveTimeout = 50000 TelnetControl.TerminalType = "vt100" TelnetControl.Connect(TcpSession) TelnetControl.ReadToDelimiter("Name:") 'Send the Username TelnetControl.Write(username + vbCrLf) 'Manually read in the Password prompt TelnetControl.ReadToDelimiter("Password:") 'Send The Password TelnetControl.Write(username + vbCrLf) 'Finally Read up to the command paramter. TelnetControl.ReadToDelimiter(":>") 'Send The COMMAND TelnetControl.Write(command + vbCrLf) SendText(TelnetControl.ReadToCount(A, B, C), textmessage, username) But i do not know what A, B, C are supposed to be or mean |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted September 12, 2011 1:55 PM Hello, As is described in the help documentation for this method, A is an array of bytes to read into, B is the offset into the byte array at which the bytes are written to, and C is count, the number of bytes you want to read off of the socket/connection. example: Dim byteArrayBuffer() As Byte = New Byte(1023) {} TelnetControl.ReadToCount(byteArrayBuffer, 0, 1024) Based on your description though, I would recommend just using a read loop, instead of ReadToCount, so that the number of bytes you read isn't limited: Dim s As String = "" 'Receive data when it is sent by the remote host Dim buffer() As Byte = New Byte(1023) {} Do While TelnetControl.State <> ConnectionState.Closed s = s + TelnetControl.Read(buffer, 0, 1024).ToString() Loop 'do something with string s here. |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted September 12, 2011 3:45 PM I was thinking about your issue some more, and I think it would actually be even better to use ReadToEnd(). Set the timeout, ReadToEnd(), and wait for the timeout exception. In the error handler, you can then access the DataRead field in the exception for the data. This way you can ensure that you read all of the data (don't need to specify the count of data to read, and there's no way to set it too low), and it will only read for 30 seconds. |
creatinggenius From: Saratoga Springs, NY USA Posts: 10 Member Since: 08/29/11 |
posted September 13, 2011 10:02 AM Thanks i would like to use the Read to end. Could you send a example code including the error handler. |
Nick B (Admin) From: Utica, NY USA Posts: 619 Member Since: 05/25/10 Extra Support Options Custom Application Development |
posted September 13, 2011 11:26 AM Try Telnet.ReadToEnd() Catch ex As Dart.Telnet.DataException 'use ex.DataRead here End Try |
creatinggenius From: Saratoga Springs, NY USA Posts: 10 Member Since: 08/29/11 |
posted September 13, 2011 12:10 PM Works good! thanks. |
Reply | PowerTCP Telnet for .NET Topics | Forums |
This site is powered by PowerTCP WebServer for ActiveX |