Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Send file via DatagramSocket

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Thanked 0 Times in 0 Posts

    Default Send file via DatagramSocket

    I want to send a object (which contains a File) to a server via datagramSockets aka (UDP)
    So the steps are:

    1 - create object: Obj o = new Obj (File, String, int).
    2 - convert file to bytearray
    3 - convert object to byte array

    Then, having created the datagram sockets procedures i have.

    4 - socketUdp.send (byteArray_of_Object)

    The problem is: When the server try to receive the data it throws an exception saying: "Ocupied port".
    But if i dont include the File in the object everything goes OK.

    Any ideas why it could be happening ?

  2. #2
    Junior Member
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Default Re: Send file via DatagramSocket

    Files, unlike strings and ints (any primitive type for that matter) are not serializable.
    So if you want to send a file via a socket (may the protocol be UDP or TCP) you are going to have to send the file's name and the bytes in it over to the server which will first have to create a new file with the received filename and then write the received bytes in it.

Similar Threads

  1. send image file from java to php broken pipe exception occured
    By ashi123 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 21st, 2011, 02:53 PM
  2. [SOLVED] Send File (path) as argument to method
    By efluvio in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 31st, 2011, 01:13 PM
  3. Platform Issue XP vs 7 ?? Send File Accross Network
    By dumb_terminal in forum Java Networking
    Replies: 0
    Last Post: April 12th, 2011, 02:44 PM
  4. Send Scanned File to E-mail
    By babywiz21 in forum Java Theory & Questions
    Replies: 1
    Last Post: April 2nd, 2011, 08:40 PM
  5. [SOLVED] Server Client does not send file
    By Kakashi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 10th, 2011, 12:38 PM