Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bytes transmision problem trough sockets

Status
Not open for further replies.

Raywall

Programmer
Oct 1, 2003
51
RO
I have to send a gif from a client to server.
I have used sockets and DataInputStream and PrintWriter to stream the data.
The problem is that the server recives incorect data; a few bytes are not recognized.This is the source gif sent by the client:
//****************************************
GIF89a2 2 ³ RPPÅÄÄ}||·¶¶ÔÓÓ`^^¨§§&$$522ââ⌊ŠCAAommš˜˜ÿÿÿ!ù , 2 2 ðÉI«½8ëÍ»ÿ`(Ždižhª®lë¾p,Ïtmßx®ï|ïÿÀ pH,?Èaá<Š\!? €PÚ€P rÄà Dw‡†•HœqЊÁ &S|8
 w7 t‹I”•–—˜™ ;
//****************************************
And this is what the server recives:
//***************************************
GIF89a2 2 ³ RPPÅÄÄ}||·¶¶ÔÓÓ`^^¨§§&$$522âââ???CAAomm???ÿÿÿ!ù , 2 2 ðÉI«½8ëÍ»ÿ`(?di?hª®lë¾p,Ïtmßx®ï|ïÿÀ pH,?Èaá<?\!? ?PÚ?P rÄà Dw???H?qÐ?Á &S|8
 w7 t?I?????? ;
//***************************************
Notice the last bytes from the recived transmision: t?I?????? .
Please tell me why is this happening. Should i send the data using byte transmision instead of the PrintWriter.println() method?
Thanks in advance.
 
Should i send the data using byte transmision instead of the PrintWriter.println() method?

I reckon so.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
You can't send byte data using an stream to send ASCII characters !!!

Use a DataOutputStream.

--------------------------------------------------
Free Database Connection Pooling Software
 
my bad sedj i admit.
The thing is the I implemented a chat and for that println worked just fine. And now i had to add this last feature and i hoped i won't be forced to change the transmision method.
Guess I was wrong..
 
Its easy to recreate a PrintWriter.println() call :

Code:
byte[] newLineBytes = "\n".getBytes();
DataOutputStream dos ...

dos.write(newLineBytes);
dos.flush();

Thats basically all it does ...

--------------------------------------------------
Free Database Connection Pooling Software
 
ok i make the transmision corect.
But now i think that i have to read from the file(the gif) the same way(byte rows) and i don't know how...
 
You can read a file like this :

Code:
File f = new File("mygif.gif");
byte[] data = new byte[(int)f.length()];
FileInputStream fis = new FileInputStream(f);
f.read(data);
fis.close();

// data now contains your gif.

--------------------------------------------------
Free Database Connection Pooling Software
 
Ohh i finnaly made it. Ty for your help sedj.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top