Hi everyone..
i m developing an application to backup files\directories to a server..
i initially developed it in RMI but then to make it possible to run over Internet i made some modifications and used sockets..
I have designed few packets for sending login details, file information to be backed-up, file data, etc. to server. The server parses the packets, identifies the type of packet and takes action accordingly.
Problem is that the application works fine, throws no exception but the data transfered gets corrupted. This is the case only with data packet.
Other packets; like login packet, file information packet; aint get corrupted. The action taken on receipt of these packets are as desired.
Sometimes the data is not corrupted while most of the time it is..
I test the app by backing up an image file so that its easy to check the backed-up file. I test the application on same PC.
I have created a thread to listen incoming data on client and server side, each.
Right now m testing the app on same PC.
Can anyone guide me what might be wrong with the code?? Any do's or dont's in socket programming in JAVA...???
I m using byte array as packets and DataInputStream and DataOutputStream for reading and writing the packets.
Thank you,
Janvi
janvi.dodia
0
Newbie Poster
Recommended Answers
Jump to PostI dont know what the problem is, but instead dataInputStream and dataOutputStream, you can try BufferedInputStream and PrintWriter which I always use in socket programming in java. And a byte[4096] buffer maybe better.
Jump to PostThank you so much for ur reply..
can u please give an example as to how should i use PrintWriter to write byte array??
I got no methods to write byte array using PrintWriter and i guess converting byte array to String will give undesirable outputs. I read it somewhere …
All 8 Replies
gangsta1903
2
Junior Poster
janvi.dodia
0
Newbie Poster
gangsta1903
2
Junior Poster
janvi.dodia
0
Newbie Poster
sakthi2488
0
Newbie Poster
thexplanet
0
Newbie Poster
Riyasdeen
0
Newbie Poster
zeroliken
79
Nearly a Posting Virtuoso
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.