Forums Register Login

End of stream.

+Pie Number of slices to send: Send
I am writing a string using DataOutStream classes writeBytes method.
os.writeBytes(m_send_buffer);
On the other side I am reading using InputStream in while loop.
I am using following code on the other side(proxy server)
while((bytes_read=from_client.read(buffer))!=-1) {
to_server.write(buffer, 0, bytes_read);
to_server.flush();
}

I am gettinng blocked in the loop,I guess the reason is I am not getting end of stream.Can anyone suggest an alternate or am I doing something wrong?.
Thank!!
Arvind

}
+Pie Number of slices to send: Send
Did you close the original DataOutputStream? If it's still open, then the file may not have an end yet, so the InputStream just keeps waiting for more bytes to be read.
+Pie Number of slices to send: Send
Thanks!!.I noticed that.I tried closing the stream,which seems to close the underlying Socket.In latter part of my program I need to get an inputstream on the same socket to read the response.So when I try to get Inputstream on the socket I get SocketClosed error
java.io.IOException: Socket Closed
at java.net.PlainSocketImpl.getInputStream(PlainSocketImpl.java:421)
at java.net.Socket$1.run(Socket.java:335)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.Socket.getInputStream(Socket.java:332)
at com.sungard.omniconnect.framework.TransIp.receiveData(TransIp.java:21
6)
Other work around would be to send a flag to indicate the end of message, but this will remove the generic nature of my application.So of no use.Any other better solutions please!!
Thanks!!
Arvind
+Pie Number of slices to send: Send
Makes sense - if you want to keep using the same socket, you can't close it. (Though it would be nice if the documentation made it clear that closing a socket's OutputStream also closed the socket itself.) I suppose you could just open a new Socket later on the same port - but that may well take more resources than you want. If you want to keep the socket open, you need to establish some protocol between the input and output streams . I'd probably send a control-D character (Unicode value 4, End-of-transmission). When you read that, you know the current message is ended. That may "remove the generic nature of the application" - but I'm not sure what you mean by that anyway. Are other applications going to be trying to communicate on the same port? Is it unreasonable to expect them to follow the same protocol?
Arch enemy? I mean, I don't like you, but I don't think you qualify as "arch enemy". Here, try this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2257 times.
Similar Threads
how can i copy a file from one location to another location then delete............
BLOB Question - Any Java Guru out there?
Transferring a file across a socket connection--HELP
Reading a file from a server...
Help! Please! Problem with FileInputStream
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 02:22:27.