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.
Jump to Post
I 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 buffer maybe better.
Jump to Post
Thank 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 RepliesReply to this topic
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.