import java.io.*; import java.net.Socket; public class ClientMain { public static void main(String[] args) { String hostName = "localhost"; int portNumber = 9999; try { Socket socket = new Socket(hostName, portNumber); BufferedReader sin = new BufferedReader( new InputStreamReader(socket.getInputStream())); File file = new File("\folder\subfolder\image.jpg"); long length = file.length(); byte[] bytes = new byte[64 * 1024]; InputStream in = new FileInputStream(file); OutputStream sout = socket.getOutputStream(); int count; while ((count = in.read(bytes)) > 0) { sout.write(bytes, 0, count); } in.close(); sout.flush(); String fromServer; while (( fromServer = sin.readLine() ) != null) { System.out.println("Server: " + fromServer); } sout.close(); sin.close(); socket.close(); } catch (IOException e) { e.printStackTrace(); } } }