• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending a .txt file - DatagramSocket

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !!
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Poop goes in a willow feeder. Wipe with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic