Send file via DatagramSocket
Hi,
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 ?
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. :o