• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sending a .txt file - DatagramSocket

 
Gustavo Berndorfer Goldhardt
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,

I have never programmed using sockets before and I ask you guys for helping me. I need to build an application that sends a .txt file from the client to server using DatagramSocket. I have been looking for tutorials and samples in the internet but most of them are confusing and it is diffcult for me that have no expirience in sockets. Could anyone show me a way to start, or post samples of similar problems?

Thank you !!
 
Rob Spoor
Sheriff
Posts: 20817
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
UDP, which is used by DatagramSocket, is not the best option for sending files, as UDP does not guarantee arrival nor order. TCP, which is used by Socket, does.

Should you still need to do it, you should create a DatagramPacket with the contents as a byte[] from the text file, then send that DatagramPacket. If the file is too large you need to send multiple DatagramPackets but as said before, you will be very lucky if the packets arrive in the same order as you send them.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!