Archives for 

Socket Programming

This category gives tutorials on networking in Java.Examples also discussed.

Java Socket Programming-Transferring large sized files through socket

So far we have discussed the fundamentals of Socket programming . In a previous chapter we have discussed the file transfer using TCP. In that example we were converting the entire file object into byte array . And sending it through the socket.But that cannot be applied to large sized file.Because the heap of a JVM  cannot afford an object beyond its maximum capacity.So for transferring large sized files we need to use another approach. In this chapter we are discussing about  transferring large sized files through socket with suitable example.The file size does not have any limit in this case.So this application can be used to transfer movies of large or very large size.The java nio package has a SocketChannel component.We can use a  SocketChannel instance for  sending file. On the other side of connection , a ServerSocketChannel  accepts the connection.Read/Write operations  on a file is done with FileChannel instances

Transferring large sized files through socket


Specify a valid file as source file in .Specify a valid and existing output folder at the  while initializing the RandomAccessFile object.In the above code , we used  localHost  as address .We need to put suitable address there. Start the and then file would be sent from source to destination.  These applications can be used to transfer large sized files (like .mkv  , .mprg movies) from one machine to another.This application can be used to transfer files of  all formats.