K
Kai Thorsrud
Hi,
Thanks a lot for the short path solution to the app i'm working on by
including a Perl script ( App i'm converting from perl to .Net) for the part
i can't
do yet.
I'm communicating with a Cisco Router and i selected Sync reading since i
have an expected datapattern when this app runs.
However i thought that the read method where supposed to wait util the
entire stream was recieved before returning ?
I'm doing a write, wait for the echo to complete then i do a read to read
the result of the command i send.
The read command returnes long berfore the stream is complete. If i step
throu the code it works since i can't manage to step in the same speed as
the running app
I tried to put a 500msec sleep between the read of the echo and the read of
the result of the command (show running-config)
Am i doing this wrong ? here is my read function
Public Function ReadDataFromStream(ByVal objNetWorkStream As
NetworkStream) As String
Dim sTempBuffer As String
Dim sResultBuffer As String
Dim iBytesRead As Integer
Try
If objNetWorkStream.CanRead() Then
' When Called the Read method will wait until data is
available
iBytesRead = objNetWorkStream.Read(bReadBuffer, 0,
iReciveBufferSize)
sTempBuffer = Encoding.ASCII.GetString(bReadBuffer)
' Pull out the data we recieved into a string
sResultBuffer = Mid(sTempBuffer, 1, iBytesRead)
'DataAvailable returns true only if data is available on the
datastreams read buffer. Doing this to be sure that we fetch all the data
Do While objNetWorkStream.DataAvailable
iBytesRead = objNetWorkStream.Read(bReadBuffer, 0,
iReciveBufferSize)
sTempBuffer = Encoding.ASCII.GetString(bReadBuffer)
sResultBuffer = sResultBuffer & Mid(sTempBuffer, 1,
iBytesRead)
oEventLog.LogEvent(Me.EventLogName, "ReadDataFromStream
read: " & sTempBuffer, EventLogEntryType.Information)
Loop
End If
Catch ex As Exception
oEventLog.LogEvent(Me.EventLogName, "Failed reading from the
datastream of " & Me.RemoteHost & ":" & Me.RemotePort,
EventLogEntryType.Error)
printDebugMessage(ex.ToString())
End Try
ReadDataFromStream = sResultBuffer
End Function
Thanks a lot for the short path solution to the app i'm working on by
including a Perl script ( App i'm converting from perl to .Net) for the part
i can't
do yet.
I'm communicating with a Cisco Router and i selected Sync reading since i
have an expected datapattern when this app runs.
However i thought that the read method where supposed to wait util the
entire stream was recieved before returning ?
I'm doing a write, wait for the echo to complete then i do a read to read
the result of the command i send.
The read command returnes long berfore the stream is complete. If i step
throu the code it works since i can't manage to step in the same speed as
the running app
I tried to put a 500msec sleep between the read of the echo and the read of
the result of the command (show running-config)
Am i doing this wrong ? here is my read function
Public Function ReadDataFromStream(ByVal objNetWorkStream As
NetworkStream) As String
Dim sTempBuffer As String
Dim sResultBuffer As String
Dim iBytesRead As Integer
Try
If objNetWorkStream.CanRead() Then
' When Called the Read method will wait until data is
available
iBytesRead = objNetWorkStream.Read(bReadBuffer, 0,
iReciveBufferSize)
sTempBuffer = Encoding.ASCII.GetString(bReadBuffer)
' Pull out the data we recieved into a string
sResultBuffer = Mid(sTempBuffer, 1, iBytesRead)
'DataAvailable returns true only if data is available on the
datastreams read buffer. Doing this to be sure that we fetch all the data
Do While objNetWorkStream.DataAvailable
iBytesRead = objNetWorkStream.Read(bReadBuffer, 0,
iReciveBufferSize)
sTempBuffer = Encoding.ASCII.GetString(bReadBuffer)
sResultBuffer = sResultBuffer & Mid(sTempBuffer, 1,
iBytesRead)
oEventLog.LogEvent(Me.EventLogName, "ReadDataFromStream
read: " & sTempBuffer, EventLogEntryType.Information)
Loop
End If
Catch ex As Exception
oEventLog.LogEvent(Me.EventLogName, "Failed reading from the
datastream of " & Me.RemoteHost & ":" & Me.RemotePort,
EventLogEntryType.Error)
printDebugMessage(ex.ToString())
End Try
ReadDataFromStream = sResultBuffer
End Function