Reputation: 66
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
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
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):
BTW, may I ask what your profession is?
Upvotes: 1