Which socket programming is best (TCP/UDP)? [close

2019-09-08 09:31发布

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.

3条回答
倾城 Initia
2楼-- · 2019-09-08 09:53

UDP programmin but it will be difficult to implement

查看更多
干净又极端
3楼-- · 2019-09-08 10:08

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.

查看更多
Rolldiameter
4楼-- · 2019-09-08 10:11

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:

查看更多
登录 后发表回答