0

My client program wants to send a huge file to the server and in return the server program returns a double or triple sized file.

My question is, which approach should I use? Either TCP or UDP.

mike
  • 4,929
  • 4
  • 40
  • 80
AJ.
  • 4,526
  • 5
  • 29
  • 41
  • Do you have to use a socket? HTTP, FTP have each been suggested or you could directly push the file across the network. – Tim Sep 19 '13 at 13:18
  • Yes, I want the answer only regarding socket programming and I think I got it. – AJ. Sep 19 '13 at 13:32

3 Answers3

5

You could utilize FTP (File Transfer Protocol) for your use case.
It is very common and you can use it with java to get or to upload files to the FTP server.

Also take a look at this question on SO: File upload in Java through FTP


If you still want to implement it yourself, I would recommend using TCP, since it offers you some services:

Community
  • 1
  • 1
mike
  • 4,929
  • 4
  • 40
  • 80
4

This question is too broad, but the answer is probably TCP; if you're needing to transfer a file, TCP provides ordering and retransmission services that UDP doesn't, and there's no reason to reinvent the wheel.

Along those lines, though, why reinvent HTTP? This sounds like a classic case for using a Web server.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
-7

UDP programmin but it will be difficult to implement

Ashish
  • 1,943
  • 2
  • 14
  • 17
  • 1
    Unlikely. File transfer kinda needs reliable transmission. – chrylis -cautiouslyoptimistic- Sep 19 '13 at 13:05
  • 1
    Not really, since UDP is a protocol that does **not** guarantee that the packets come in, or come in in order. It's definitely not 'best and easy to implement'. – mike Sep 19 '13 at 13:09
  • TCP Doesn't guarantee delivery either, not saying that UDP is the better choice but I think that should be clarified. – Tim Sep 19 '13 at 13:14
  • 1
    i know that TCP is Better but for large file UDP perform better as UDP can send large packet in one go – Ashish Sep 19 '13 at 13:15
  • 1
    @Tim You should read up on TCP. http://en.wikipedia.org/wiki/Transmission_Control_Protocol – mike Sep 19 '13 at 13:19
  • 2
    @Ashish Could be that it performs better, but the point is, it is not easier to implement. – mike Sep 19 '13 at 13:21
  • 1
    @Ashish unless it is dropped or fragmented. The larger the packet, the more likely it will be dropped. BTW a single UDP packet cannot be more than 64 KB, which might be a problem if you have files larger than this. – Peter Lawrey Sep 19 '13 at 13:22
  • @Ashish "Large packet in one go"? What are you *talking* about? – chrylis -cautiouslyoptimistic- Sep 19 '13 at 13:23
  • @mike dude see AJ comment chrylis post thats y i told him to use UDP – Ashish Sep 19 '13 at 13:25
  • 2
    @chrylis UDP supports packets of up to 64 KB, whereas TCP is typically 1.5 KB of 9 KB. While you can send 64 KB packets, there is no guarantee it will be supported by your network infrastructure and arrive of course. – Peter Lawrey Sep 19 '13 at 13:26
  • @peter lawrey dude see AJ comment chrylis post thats y i told him to use UDP – Ashish Sep 19 '13 at 13:26
  • @Mike, There is no way that delivery can be guaranteed as there are two many points of failure. To write code that pushes out a message and assumes success is asking for disaster - I've seen it. For every developer that is out there that believes that, there is another that has to account for someone else's misconception. – Tim Sep 19 '13 at 13:48
  • The generally accepted UDP payload size across the Interment is 534 bytes. Within an Ethernet it is limited by the Ethernet frame size of around 1500 bytes. Within a single host you can achieve 65507 bytes. Merely naming one protocol over another without giving any reasons doesn't constitute an answer – user207421 Sep 19 '13 at 23:32