Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Data not sent after flush() with a DataOutputStream on a Socket

Reply
Thread Tools

Data not sent after flush() with a DataOutputStream on a Socket

 
 
Florent Coué
Guest
Posts: n/a
 
      08-07-2003
Hi,

when I write and flush some data (several packets => several write()) on a
DataOutputStream associated to a Socket, from a certain quantity of data,
the last sent data are lost.

Is there any problem with the method flush() of OutputStream ?

Do you another solution that have a sleep() before closing socket ?

Here is a example of my program :

====================
Socket socket = new Socket();
socket.connect(new InetSocketAddress(adresseIP, port), timeout);
DataOutputStream output = new
DataOutputStream(socket.getOutputStream());
...


for (int i = 0; i < listData.size(); j++)
{
output.write( (byte[])listData.elementAt(i) );
}
output.flush();

output.close();
socket.close();
=======================

Thanks for help
Florent


 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      08-07-2003
On Thu, 7 Aug 2003 17:56:48 +0200, Florent Coué wrote:
> when I write and flush some data (several packets => several
> write()) on a DataOutputStream associated to a Socket, from a
> certain quantity of data, the last sent data are lost.


I suspect that the problem is at the far end of the connection. What
does the receiver of the data look like?

You could also try socket.shutdownOutput(), wait for EOF on the
*InputStream* associated with the socket (indicating that the remote
has closed), and finally socket.close().

/gordon

--
[ do not send me private copies of your followups ]
g o r d o n . b e a t o n @ e r i c s s o n . c o m
 
Reply With Quote
 
 
 
 
EJP
Guest
Posts: n/a
 
      08-08-2003
The problem here is that you aren't taking any notice of the return
value of write(). It is not guaranteed to write the number of bytes you
ask it to, and you have to cope with the resulting situation.

"Florent Coué" wrote:
>
> Hi,
>
> when I write and flush some data (several packets => several write()) on a
> DataOutputStream associated to a Socket, from a certain quantity of data,
> the last sent data are lost.
>
> Is there any problem with the method flush() of OutputStream ?
>
> Do you another solution that have a sleep() before closing socket ?
>
> Here is a example of my program :
>
> ====================
> Socket socket = new Socket();
> socket.connect(new InetSocketAddress(adresseIP, port), timeout);
> DataOutputStream output = new
> DataOutputStream(socket.getOutputStream());
> ...
>
> for (int i = 0; i < listData.size(); j++)
> {
> output.write( (byte[])listData.elementAt(i) );
> }
> output.flush();
>
> output.close();
> socket.close();
> =======================
>
> Thanks for help
> Florent

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataOutputStream how make wirte dev/null Rafal\(sxat\) Java 7 06-14-2009 01:35 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
DataOutputStream: scrittura low byte first 3470816911@vodafone.it Java 1 09-15-2008 04:25 PM
DataOutputStream/DataInputStream JScoobyCed Java 2 08-11-2004 08:21 AM
Re: Data not sent after flush() with a DataOutputStream on a Socket Florent Coué Java 0 08-08-2003 01:19 PM



Advertisments