• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

End of stream.

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

}
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Arvind Chavar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic