Hi,
I am working on a small java client and server program pair which at
client side packetizes data (such as jpeg image file) and appends some
header info for each packetized packet. At the server side, the
packetized data is reassembled back into the original image.
At client side I am using DataOutputStrea m/BufferedOutputS tream:
DataOutputStrea m data_out = new DataOutputStrea m(
new BufferedOutputS tream(client_so cket.getOutputS tream()));
data_out.writeI nt(seq_Num); // part
data_out.writeL ong(time_stamp) ; // of
data_out.writeI nt(image_size); // header
data_out.writeI nt(length); // for each packetized data
data_out.write( data, 0, length); // Packetized Data
On the server side I read back packetized data back sent by client and
later reassemble it back to original image:
DataInputStream data_in = new DataInputStream (
new BufferedInputSt ream(connection _socket.getInpu tStream()));
for ( ; ; ) {
seq_num = data_in.readInt ();
time = data_in.readLon g();
size = data_in.readInt ();
dlength = data_in.readInt ();
System.out.prin tln(seq_num + ", " + time + ", " + size + ", "
+ dlength);
byte[] p_data = new byte[dlength];
rlen = data_in.read(p_ data, 0, dlength);
Here's my problem
=============== ==
When I read data back at the server side I get corrupted data when I
parse byte packetized data, that is data from DataInputStream data_in
Here's the output:
seq_num=1, time=1067733150 359, size=65366, dlength=1000
Received Packet No. 1 from Node A . . .
seq_num=2, time=1067733150 361, size=65366, dlength=1000
Received Packet No. 2 from Node A . . .
seq_num=3, time=1067733150 363, size=65366, dlength=1000
Received Packet No. 3 from Node A . . .
seq_num=2134239 293, time=5009899065 144553973, size=-2132742293,
dlength=1480003 007
Exception in thread "main" java.lang.OutOf MemoryError
Any ideas what causes this error? Any help would be greatly appreciated...
-John 2 4805
John Thorner wrote: On the server side I read back packetized data back sent by client and later reassemble it back to original image:
DataInputStream data_in = new DataInputStream ( new BufferedInputSt ream(connection _socket.getInpu tStream()));
for ( ; ; ) { seq_num = data_in.readInt (); time = data_in.readLon g(); size = data_in.readInt (); dlength = data_in.readInt (); System.out.prin tln(seq_num + ", " + time + ", " + size + ", " + dlength);
byte[] p_data = new byte[dlength]; rlen = data_in.read(p_ data, 0, dlength);
Here's my problem =============== == When I read data back at the server side I get corrupted data when I parse byte packetized data, that is data from DataInputStream data_in
Here's the output:
seq_num=1, time=1067733150 359, size=65366, dlength=1000 Received Packet No. 1 from Node A . . . seq_num=2, time=1067733150 361, size=65366, dlength=1000 Received Packet No. 2 from Node A . . . seq_num=3, time=1067733150 363, size=65366, dlength=1000 Received Packet No. 3 from Node A . . . seq_num=2134239 293, time=5009899065 144553973, size=-2132742293, dlength=1480003 007 Exception in thread "main" java.lang.OutOf MemoryError
Any ideas what causes this error? Any help would be greatly appreciated...
The DataInputStream .read(byte[], int, int) method is not guaranteed to
read all of the bytes requested. I see from your pseudo-code above you
are saving the return value; did you also check it to make sure all of
the requested bytes were read?
Ray
Raymond DeCampo wrote: John Thorner wrote:
On the server side I read back packetized data back sent by client and later reassemble it back to original image:
DataInputStream data_in = new DataInputStream ( new BufferedInputSt ream(connection _socket.getInpu tStream()));
for ( ; ; ) { seq_num = data_in.readInt (); time = data_in.readLon g(); size = data_in.readInt (); dlength = data_in.readInt (); System.out.prin tln(seq_num + ", " + time + ", " + size + ", " + dlength);
byte[] p_data = new byte[dlength]; rlen = data_in.read(p_ data, 0, dlength);
Here's my problem =============== == When I read data back at the server side I get corrupted data when I parse byte packetized data, that is data from DataInputStream data_in
Here's the output:
seq_num=1, time=1067733150 359, size=65366, dlength=1000 Received Packet No. 1 from Node A . . . seq_num=2, time=1067733150 361, size=65366, dlength=1000 Received Packet No. 2 from Node A . . . seq_num=3, time=1067733150 363, size=65366, dlength=1000 Received Packet No. 3 from Node A . . . seq_num=2134239 293, time=5009899065 144553973, size=-2132742293, dlength=1480003 007 Exception in thread "main" java.lang.OutOf MemoryError
Any ideas what causes this error? Any help would be greatly appreciated... The DataInputStream .read(byte[], int, int) method is not guaranteed to read all of the bytes requested. I see from your pseudo-code above you are saving the return value; did you also check it to make sure all of the requested bytes were read?
Ray
Thanks for the tip. I should have used readFully() instead. It works!!! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Alexandros Karypidis |
last post by:
Hi all,
I would like some advice regarding the following design issue:
I would like to be able to exchange data in XDR format. I was thinking of
writing a pair of I/O streams in the same fashion as DataInputStream and
DataOutputStream. I am ambivalent as to whether I should:
(a) subclass DataInputStream / DataOutputStream and override what is needed
(b) subclass FilterInputStream / FilterOutputStream and implement the
|
by: Patrick |
last post by:
Hello all!
I am porting an application from C++ to Java and have run into a
problem using the DataInputStream reader object. The file I am trying
to read in is anywhere from 20 to 60 MB and has a short (25 lines or
so) ASCII text "header". The file structure is a double dimensioned
array of objects. The ASCII header defines how many "columns" (the
first array index) there will be in the file. After the ASCII header,
the first value is...
|
by: JNY |
last post by:
I am using random to generate random numbers, thus:
int x,y;
for (y = 0;y < 5;y++)
{
x = random(50);
cout << x;
}
|
by: Stavros Christoforou |
last post by:
Hello everyone,
I was wondering if someone could help me with an issue I have in C++. I
want to select random points within the volume of a sphere. I know how
to get random numbers using srand() and rand(), but have no idea how to
do that within a more complicated geometry. Any help would be greatly
appreciated..
Regards
Stavros
|
by: Toby Newman |
last post by:
I need to randomly choose one of four paths in my program. Using the
tools I know, the best way I can think to do it is by doing something
like the following:
//==============================
#include <stdlib.h> //allow rand() function
int i;
i = rand (); // i = any number of the set or
if (0<=i<(4294967295/4))
| |
by: fieldfallow |
last post by:
Hello all,
Is there a function in the standard C library which returns a prime
number which is also pseudo-random?
Assuming there isn't, as it appears from the docs that I have, is there
a better way than to fill an array of range 0... RAND_MAX with
pre-computed primes and using the output of rand() to index into it to
extract a random prime.
|
by: Kza |
last post by:
Hi, I am currently using xerces sax parser for c++, (I use DOM too, but
I think SAX is more relevant here) for processing and displaying fairly
large xml files. Usually I give xerces a filename, and it parses it and
thats all good. But the customer needs more features.
Feature 1: A progress display. I have tried a few times now to find a
way of asking xerces how far through a file it is in bytes, but no
luck. (I did try a per element...
|
by: duffint |
last post by:
Hi there,
I have this script that I need some direction in; it's mangled my head
a bit.
I want to be able to stick links around six random words; these links
are then popup ads.
I saw kind of a similar thing on a site a while ago.
|
by: Robbie Hatley |
last post by:
I needed a quick program called "random" that gives a random
positive integer from n1 to n2. For example, if I type
"random 38, 43", I want the program to print a random member
of the set {38, 39, 40, 41, 42, 43}.
Also, I read in my compiler's documentation the following:
To get a random number in the range 0..N, use rand()%(N+1).
Note that the low bits of the rand's return value are not
very random, so rand()%N for small values of N...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: 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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |