Ravi
Ravi

Reputation: 66

File Transfer via Internet ( using java)

I've a java(swing) application running on server and client(or assume two different

computers),These two are connected through Internet not by LAN or WAN..The client has to send

some data (around 200 kb) to the server.Which method is preferable for transferring data..I used

TCP through LAN,but it's working slow through Internet..So can I use UDP for internet ? If yes, I don't

know how to divide my data into chunks and send it & again re-assemble the data at the server.

I am really thankful if source code is provided for UDP transfer(bulk data in java).

thanks in advance..

Upvotes: 1

Views: 2317

Answers (2)

ThomasRS
ThomasRS

Reputation: 8287

Use TCP, it does exactly what you want in a way which is much better than you can hope to implement on your own. If you have low bandwidth, transfer in the background or just wait - there is nothing you can do with that.

Read your data in byte arrays and write them as a whole - see DataInputStream.readFully(). Flush the output at the end of the writing.

Edit:If you want to send multiple images, one after the other, you can do video compression - it is designed to be efficient just at that.

Upvotes: 4

Ingo
Ingo

Reputation: 36339

Ravi is struggeling for some days now with this problem. Now UDP is expected to bring help, but, of course, it won't!

Ravi, I give you some more hints for free (as you have not upvoted even one of the 7 answers you have received until now, I guess the reputation system in StackOverflow is and remains a mystery to you):

  1. Computer 2D-images are nothing more than a 2 dimensional array of pixels, i.e. color values (usually int values).
  2. The BufferedImage class has methods to get and set each pixel individually, I told you yesterday.
  3. Two equal sized Images are different, if there is a coordinate x,y where the corresponding pixel in one image is not the same as in the other image.

BTW, may I ask what your profession is?

Upvotes: 1

Related Questions