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 ReadDataFromStr eam(ByVal objNetWorkStrea m As
NetworkStream) As String
Dim sTempBuffer As String
Dim sResultBuffer As String
Dim iBytesRead As Integer
Try
If objNetWorkStrea m.CanRead() Then
' When Called the Read method will wait until data is
available
iBytesRead = objNetWorkStrea m.Read(bReadBuf fer, 0,
iReciveBufferSi ze)
sTempBuffer = Encoding.ASCII. GetString(bRead Buffer)
' 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 objNetWorkStrea m.DataAvailable
iBytesRead = objNetWorkStrea m.Read(bReadBuf fer, 0,
iReciveBufferSi ze)
sTempBuffer = Encoding.ASCII. GetString(bRead Buffer)
sResultBuffer = sResultBuffer & Mid(sTempBuffer , 1,
iBytesRead)
oEventLog.LogEv ent(Me.EventLog Name, "ReadDataFromSt ream
read: " & sTempBuffer, EventLogEntryTy pe.Information)
Loop
End If
Catch ex As Exception
oEventLog.LogEv ent(Me.EventLog Name, "Failed reading from the
datastream of " & Me.RemoteHost & ":" & Me.RemotePort,
EventLogEntryTy pe.Error)
printDebugMessa ge(ex.ToString( ))
End Try
ReadDataFromStr eam = sResultBuffer
End Function 4 3356
"Kai Thorsrud" <ka******@thisp artgoesaways.st art.no> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. .. 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)
You need to do something like this:
iBytesRead = 0
totalBytesExpec ted = 1024 * 47
do while iBytesRead < totalBytesExpec ted
iBytesRead += objNetWorkStrea m.Read(bReadBuf fer,
iBytesRead,iRec iveBufferSize)
loop
David
But then i need to know the expected amount of data to be recieved before i
recieve the data ?
Wouldn't that make the read function pretty useless at communicating with a
telnetserve as a Cisco router ?
I'm gonna use this read function to poll 50 routers for their config file
and the config file differs in size for each router.
Isn't there a more generic approach of solving this ? I really didn't like
to but a sleep command there before i do a read since you never now what you
get in return.
This will give me the same problem... Or am i missing a point here ?
Kai You need to do something like this:
iBytesRead = 0 totalBytesExpec ted = 1024 * 47 do while iBytesRead < totalBytesExpec ted iBytesRead += objNetWorkStrea m.Read(bReadBuf fer, iBytesRead,iRec iveBufferSize) loop
David
"Kai Thorsrud" <ka******@thisp artgoesaways.st art.no> wrote in message
news:O6******** ******@TK2MSFTN GP10.phx.gbl... But then i need to know the expected amount of data to be recieved before
i recieve the data ? Wouldn't that make the read function pretty useless at communicating with
a telnetserve as a Cisco router ? I'm gonna use this read function to poll 50 routers for their config file and the config file differs in size for each router.
Isn't there a more generic approach of solving this ? I really didn't like to but a sleep command there before i do a read since you never now what
you get in return. This will give me the same problem... Or am i missing a point here ?
I assumed that you know how big the files were.
As far as I know you have 4 options with TCP/IP:
1) Read until you have received a agreed number of bytes.
2) Read until the remote host closes the connection (ie read to the end).
3) Read until you see a special token in the stream.
4) Read until a read times out.
David
Thanks alot... I solved it by watching for a specific pattern in the
recieved stream :) Works like a dream.... jiiipiii
B Regards
Kai I assumed that you know how big the files were.
As far as I know you have 4 options with TCP/IP:
1) Read until you have received a agreed number of bytes.
2) Read until the remote host closes the connection (ie read to the end).
3) Read until you see a special token in the stream.
4) Read until a read times out.
David
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: cmjman |
last post by:
I have an issue where networkStream.Write doesn't perform its write
downstream from my client program until the network stream is closed.
I then see the data that was sent appear on the other side.
I am sending a small amound of data and read where data wasn't sent
until the buffer reached a larger size. However, there is a
TcpClient property call NoDelay that is suppose to eliminate this
delay. Here is a snippet of my code below. Can...
|
by: 0to60 |
last post by:
I have a class that wraps a TcpClient object and manages all the async
reading of the socket. It works really nice, and I use it all over the
place. But there's this ONE INSTANCE where I create one of these things and
it WON'T read data. If I set a breakpoint in my EndRead callback, it never
goes off. NOTHING is different from anywhere else I use this class, its
just this one place.
Now, if I create a second constructor for my class...
|
by: Casey Watson |
last post by:
Hi :)
I'm having some major trouble with an XML Client/Server application that I
am writing. I am using NetworkStream with CryptoStream to Read and Write
XML between computers. Now, whenever I write the XML, the Server section
which uses the XMLTextReader Class will not accept EndElements period, and
neither the ReadStartElement or ReadEndElement will work properly. However,
if I only send to WriteStartElements over the network, the...
|
by: kmacintyre |
last post by:
I am trying to us a simple NetworkStream to transfer a file over tcp. This
works most of the time, but one specific file never downloads(.mdb file). It
seems to close the socket and I get an "unable to write data to transport
connection" error. I have tried multiple ways to transfer this
file(including remoting, sockets without network stream) and downloaded
different examples of client/server byte transfer, all with the same result....
|
by: Ryan |
last post by:
Hi,
I am confused with how NetworkStream works.
My application needs to handle heavy requests sent through TCP socket
connection. I use NetworkStream.Read method to get the stream data. The
| |
by: Al Wilkerson |
last post by:
Hey,
Has anyone ever got a "Unable to read data from transport connected" message
after reading data from a streamreader composed of a networkstream.
For example:
Server
TcpListener tcpServer = new TcpListener(localAddr,port);
|
by: DaveR |
last post by:
I have a background thread to accept and process TCP/IP connections.
When the application shuts down I want to gracefully terminate it.
The thread will block in NetworkStream.Read() waiting for data. I
expected that shutting down the TcpListener would unblock the Read()
and cause an exception, or return 0 bytes. But it does not work.
Relevant parts of the code are shown below. If a client connects, the
stream blocks in its Read()...
|
by: |
last post by:
I've got a basic "chat" infrastructure that can send objects across the wire, but I'm running into a few issues with trying to send multiple messages and things behaving differently in debug and release...
Is there anyone out there that considers themselves a threading / sockets / serialization guru? Not sure if it's appropriate to post an entire project here and the issues discussion is probably a bit too complex for newsgroup back and...
|
by: shahla.saeed |
last post by:
hi,
plzz check my code and let me know where the problem is
lying...becuase whenever i try to tansfer the file of 573KB(mp3) it
just tranfer few Kb of file(Somtimes 5.2Kb,somtimes 32Kb..every time i
run the program).....but when i watch the transfering of bytes by
debuging it.(RED dot on while(nfs.CanRead) )..it shows that complete
bytes are transfered.(in my case i-e 573Kb)....i am unable to
understand whats going wrong in my program....
|
by: littleIO |
last post by:
Hi,
I'm stuck on a very simple problem and just cant seem to get around it, little help would be much appreciated.
I have a server which listens, receives calls, processes them and sends back the results to clients.
The code below makes the client application not to respond. Client can send data but is stuck in the process of waiting information back from the server.
Any ideas?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |