473,769 Members | 5,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Double streams

Hello.

Having an issue with double streams... for a lack of a better name. :)

I have the following two streams:
- FooInputStream, fis, extending InputStream
- FooOutputStream , fos, extending OutputStream

These each have a piped stream as a local variable, so:
- fos has a PipedOutputStre am, pos
- fis has a PipedInputStrea m, pis

So pis and pos are initalized and connected, and are passed to fis and
fos, respectively.

What i wanted to do was write to fos, which would then delegate the
call to pos, and then i could read from fis, which would read from
pis. So the writes are fine, and the read in pis returns fine, but
then it just seems to hang. If i close any of the ouputstreams, it
returns, and everything is fine. But then i can't use the
outputstreams, and i need to do that.

Can any explain what's going on? Maybe a push in the right direction
as to how to solve it?

Regards,
Carsten H. Pedersen
Feb 13 '06 #1
9 3210

"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader1.cyber city.dk...
Hello.

Having an issue with double streams... for a lack of a better name. :)

I have the following two streams:
- FooInputStream, fis, extending InputStream
- FooOutputStream , fos, extending OutputStream

These each have a piped stream as a local variable, so:
- fos has a PipedOutputStre am, pos
- fis has a PipedInputStrea m, pis

So pis and pos are initalized and connected, and are passed to fis and
fos, respectively.

What i wanted to do was write to fos, which would then delegate the call
to pos, and then i could read from fis, which would read from pis. So the
writes are fine, and the read in pis returns fine, but then it just seems
to hang. If i close any of the ouputstreams, it returns, and everything is
fine. But then i can't use the outputstreams, and i need to do that.

Can any explain what's going on? Maybe a push in the right direction as to
how to solve it?


Do you flush the streams?

Is the reading and writing done in seperate threads?

- Oliver
Feb 14 '06 #2
Oliver Wong wrote:
Do you flush the streams?

Is the reading and writing done in seperate threads?

- Oliver


Well, i tried flushing. It doesn't work. Since the "outer" inputstream
gets what it needs, there shouldn't be a reason to flush the
outputstreams.. . or should there?

Reading and writing are in seperate threads, yeah. Each of the four
streams are in their own thread.

As i wrote, the "inner" inputstream returns to the "outer" inputstream
with the bytes written, but then it just stops, as if it is waiting
for the outputstreams to close. And if i close any of the
outputstreams, everything is fine.

/Carsten
Feb 14 '06 #3

"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader2.cyber city.dk...
Oliver Wong wrote:
Do you flush the streams?

Is the reading and writing done in seperate threads?

- Oliver
Well, i tried flushing. It doesn't work.


When you say "It doesn't work", it's not clear to me what the problem
is. Exceptions being thrown? Application deadlocks? Characters arrive in
random order? etc.
Since the "outer" inputstream gets what it needs, there shouldn't be a
reason to flush the outputstreams.. . or should there?
Closing an output stream in itself should not "unblock" the input
stream, but usually when an output stream closes, it first flushes itself.
That is why I ask if you tried flushing.

Reading and writing are in seperate threads, yeah. Each of the four
streams are in their own thread.


This is strange to me. I expected for there to be two threads, not four.
One thread is producing data which is pushes into the FooOutputStream , which
then forwards the data to the PipedOutputStre am (all within the same
thread). Then, a second thread, reads from the FooInputStream, which then
requests data from the PipedInputStrea m, and then consumes the data.

- Oliver

Feb 14 '06 #4
Oliver Wong wrote:
Well, i tried flushing. It doesn't work.

When you say "It doesn't work", it's not clear to me what the problem
is. Exceptions being thrown? Application deadlocks? Characters arrive in
random order? etc.


Well, it does not change anything in what's going on. So a deadlock of
some sort i would guess. The characters arrive in the order they
should to the inner.
Reading and writing are in seperate threads, yeah. Each of the four
streams are in their own thread.

This is strange to me. I expected for there to be two threads, not
four. One thread is producing data which is pushes into the
FooOutputStream , which then forwards the data to the PipedOutputStre am
(all within the same thread). Then, a second thread, reads from the
FooInputStream, which then requests data from the PipedInputStrea m, and
then consumes the data.


Yeah... i tried to replicate my problem on a smaller scale. I'm
fiddling with RMI. So two clients, each of whom has the Foo* Streams,
and inside these there is a Remote interface, which can call read()
and write(), respectively, on an object on the server. This object
being a stream, which extends PipedOutputStre am (or PipedInputStrea m),
and the two clients communicate with eachother with the server (and
the pipes) as a proxy.

So i just made it all local, and put them all in their seperate
threads to test it... but i still get the deadlock.

Same thing happens in the RMI scenario, though:

client1 -> client1outputst ream.write -> serveroutputstr eam.write ->
serverinputstre am.read -> client2inputstr eam.read -> deadlock (->
client2)

I would be happy to try another solution to exchange this data between
the clients, though. It's not a must to do it this way, it's just the
way that i just sorta stumbled upon. And since this error arose, and i
don't understand, i thought i'd at least attempt to solve it before
possibly moving on to another solution.

/Carsten
Feb 14 '06 #5

"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader1.cyber city.dk...
Oliver Wong wrote:
This is strange to me. I expected for there to be two threads, not
four. One thread is producing data which is pushes into the
FooOutputStream , which then forwards the data to the PipedOutputStre am
(all within the same thread). Then, a second thread, reads from the
FooInputStream, which then requests data from the PipedInputStrea m, and
then consumes the data.


Yeah... i tried to replicate my problem on a smaller scale. I'm fiddling
with RMI. So two clients, each of whom has the Foo* Streams, and inside
these there is a Remote interface, which can call read() and write(),
respectively, on an object on the server. This object being a stream,
which extends PipedOutputStre am (or PipedInputStrea m), and the two clients
communicate with eachother with the server (and the pipes) as a proxy.


How many threads does each client have, and what does each thread do?

- Oliver

Feb 15 '06 #6
Oliver Wong wrote:
Yeah... i tried to replicate my problem on a smaller scale. I'm
fiddling with RMI. So two clients, each of whom has the Foo* Streams,
and inside these there is a Remote interface, which can call read()
and write(), respectively, on an object on the server. This object
being a stream, which extends PipedOutputStre am (or PipedInputStrea m),
and the two clients communicate with eachother with the server (and
the pipes) as a proxy.


How many threads does each client have, and what does each thread do?

- Oliver


Each client only has one thread. Client A writes data to its
FooOutputStream , which writes to its associated PipedOutputStre am on
the server. Client B reads data from its FooInputStream, which reads
from its associated PipedInputStrea m (which is connected to the
PipiedOutputStr eam associated with client A) on the server. It then
blocks before data is returned from FooInputStream to client B.

If i close the output stream it returns - which means that it's
closing the output stream on the server, since calling close on the
FooOutputStream just sends to the call to the PipedOutputStre am on the
server.

/Carsten
Feb 15 '06 #7

"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader1.cyber city.dk...
Oliver Wong wrote:

How many threads does each client have, and what does each thread do?

- Oliver


Each client only has one thread. Client A writes data to its
FooOutputStream , which writes to its associated PipedOutputStre am on the
server. Client B reads data from its FooInputStream, which reads from its
associated PipedInputStrea m (which is connected to the PipiedOutputStr eam
associated with client A) on the server. It then blocks before data is
returned from FooInputStream to client B.

If i close the output stream it returns - which means that it's closing
the output stream on the server, since calling close on the
FooOutputStream just sends to the call to the PipedOutputStre am on the
server.


Okay, sorry, but I'm stumped then. =)

- Oliver

Feb 16 '06 #8
>

Okay, sorry, but I'm stumped then. =)

- Oliver


Thanks for trying, though. :) I think i'm missing something about how
streams behave. Since closing the outputstream seems to flush it, it's
gotta be close to working... maybe.

/Carsten
Feb 17 '06 #9
More code please.

"Carsten H. Pedersen" <no@nono.no> wrote in message
news:43******** *************** @dreader1.cyber city.dk...


Okay, sorry, but I'm stumped then. =)

- Oliver


Thanks for trying, though. :) I think i'm missing something about how
streams behave. Since closing the outputstream seems to flush it, it's
gotta be close to working... maybe.

/Carsten

Mar 1 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2963
by: Ronald Legere | last post by:
The new itertools stuff is pretty cool. One thing that bothers me though is that there seems to be no way to copy an iterator. How does one work around this? Is there a trick that I am missing? Without being able to 'split' an iterator, I can't think of how to do some of the cool things you can do with lazy lists in Haskell. It seems quite often you want to be able to do this 'splitting', and if I
29
4357
by: mrstephengross | last post by:
Hi all... How can I find out the number of significant digits (to the right of the decimal place, that is) in a double? At least, I *think* that's what I'm asking for. For instance: 0.103 --> 3 0.0103 --> 4 0.00103 --> 5 0.000103 --> 6 0.0000103 --> 7
5
3615
by: ferran | last post by:
Hi, I'm trying to convert a string to a long double using streams but for some reasing seems to give the wrong values, the idea is to do a precise textual conversion without roundings or truncations, I though about using strtold but this function is not portable hence that is why I'm using streams, this is what I'm doing //------------------------------------------------------- std::stringstream oStream; std::string sInput =...
3
3496
by: Tron Thomas | last post by:
What does binary mode for an ofstream object do anyway? Despite which mode the stream uses, operator << writes numeric value as their ASCII representation. I read on the Internet that it is possible to change the behavior of operator << so it will stream numeric values as their actual values when an ofstream is in binary mode. I did not, however, find any information on how this can be accomplished. What is involved in getting this...
8
2746
by: bonj | last post by:
hello I hope somebody can help me get my head around this area of 'stream' programming... I know that streams are very fashionable nowadays so hopefully there'll be lots of replies. ;-) Basically I have an operation which the input and output for are streams - a function which receives a certain 'chunk' of data each time it runs, and it runs many times until it has received all the data, in a similar way to a socket. What the...
4
3754
by: rainmaker1234 | last post by:
Its very simple in VC++. In the followeing code I have declared a String, and a double than I am taking the string and converting it into Double. getch() at the end is only to pause the screen so you can see the result. #include <conio.h> #include <iostream> using namespace std; void main ()
11
1805
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed. Is this true? So far as I know, I can only get a stream to "flow" when there is a '\r'. At that point the '\r' is turned into a '\n' and the whole stream is sent to some abstract area that is now only accessible to my programs (meanwhile, other...
2
4033
by: bonk | last post by:
Hello how do I connect streams in c# ? Imagine the followung scenario: I have a StreamWriter that writes Text to a Stream. How can I tell that Stream to pass that Data to another Stream (connect it to another output Stream) ? In java I am used to connect streams to each other via thier Constructors. For example: new BufferedWriter(new OutputStreamWriter(new FileOutputStream("soc.txt"),
1
2427
by: Chris | last post by:
I'm reading up on streams and I have two articles that seem to conflict with each other. One article describes streams and lists a few of the major ones (FileStream, Memory Stream, Network Stream, etc.). It then goes on to discuss the restriction that streams only read bytes or byte arrays that the .net framework provides a StreamReader and StreamWriter class to do type conversions to and from bytes when using streams. The second...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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,...
0
9866
tracyyun
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...
0
8876
agi2029
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...
1
7413
isladogs
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...
0
5310
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...
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3570
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.