how to send mp3,avi(large) files via socket...small files with size less than 100kb is possible but how to send large file..

Recommended Answers

All 11 Replies

What is the problem you are having with the large files?
Does the server dislike receiving too much data?

The basic mechanism is the same for any size file. Is the data arriving too fast for the client? In that case use the same socket connection to send ready/not ready messages from the client to the server to keep things synchronised.

client side file will be created..but it will be in 0kb only ...but no error...prog is attached..

Does the program work for some files and not for others?
Does the kind of file (text vs binary) make any difference?

I see you are reading the whole file into a buffer array before writing it. (Your use of a int for the file length limits you to 2GB anyway). It's more normal to have a sensible sized buffer and use copy blocks from the file to the output stream until the file is consumed, eg

byte[] data = new byte[4096]; // 4k buffer, could be much larger
int count;
while ((count = file.read(data)) != -1) {
	outbound.write(data, 0, count);
}

Plus its a bad idea to hide exceptions - better to put your code in a try block, catch any/every exception, and call its printStackTrace() method. That way you can be sure of seeing all the details for any exception.

ya working...small size file ok...but how can send larger movie file 700mb(is it possible to send)..it shows exception...


server side:

C:\Users\Sathya>java FileServer
Waiting...
Accepted connection : Socket[addr=/192.168.1.6,port=50781,localport=13267]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at FileServer.main(FileServer.java:16)

client side:

C:\Users\Sathya\test>java FileClient
Connecting...
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
        at FileClient.main(FileClient.java:16)

data can be send as a stream...is this possible(receiving side) to whether that stream is document or mp3, or picture type and can we possible to get original file name

Are you saving all of the file in memory?
Read some, write some, read some more, write some more, etc

.is this possible(receiving side) to know whether that stream is

You could send a header record with information about the data to follow.

ya working...small size file ok...but how can send larger movie file 700mb
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

That's exactly what I expected. See my previous post for the solution.

hi
i wrote client server programs for file transfer.
it copies the sent file content on a file ,created on client side.
but additionaly it stored some garbage text at the end...which also increased the size of the file.
how can i get actual file content?

Make sure you only write what was read. The read method returns the number of bytes that were read.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.