Results 1 to 3 of 3
  1. #1
    Hinty is offline Member
    Join Date
    Nov 2007
    Rep Power

    Default Server socket - send image to client


    Im new to JAVA so go easy on em please.

    I have a server and a client that can successfully connect to each other and other stuff but 1 function of the server is to send an image to the client. I can send the image but i was wondering how i would obtain certain information about the transfer. How would i obtain information such as:

    Time taken to transfer image
    average bit rate

    // Server code
    FileInputStream fis = new FileInputStream("images\\picture.jpg");
    byte[] buffer = new byte[fis.available()];;
    ObjectOutputStream oos = new ObjectOutputStream(serverSocket.getOutputStream()) ;

    // Client code
    ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
    byte[] buffer = (byte[])ois.readObject();
    FileOutputStream fos = new FileOutputStream("downloaded\\picture.jpg");

    if you need anything else explain or more info please let me know.

  2. #2
    strati1991 is offline Member
    Join Date
    Mar 2009
    Rep Power

    Default Time

    ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
    long start = System.currentTimeMillis(); // start Time in milisecons
    byte[] buffer = (byte[])ois.readObject();
    long time = System.currentTimeMillis()-start;//duration of the download
    //now can you divide the duration of the transfer throu the size of the //picture to get the average bitrate
    //to get the size of the File you can use java's RandomAccessFile class //and its method length()
    FileOutputStream fos = new FileOutputStream("downloaded\\picture.jpg");

    Maybe it is better to use a DataInputStream and the DataOutputStream to get a faster transmission
    Last edited by strati1991; 03-13-2009 at 08:39 PM.

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    Assuming all systems use NTP, you can use "System.getCurrentTimeMillis()" (or the newer ns call) on the server side, package that information into a message header, then do the same on the client side, take the difference, and that's you're transfer time.

Similar Threads

  1. send file via client - server model
    By spasavvas in forum Networking
    Replies: 15
    Last Post: 08-13-2010, 11:45 AM
  2. send/read int in a client/server app
    By dim_ath in forum New To Java
    Replies: 2
    Last Post: 01-03-2008, 02:03 PM
  3. how to send .jar files client to server
    By gobinathm in forum Networking
    Replies: 1
    Last Post: 12-25-2007, 05:05 AM
  4. Identify Client in Socket Client Server Application
    By masadjie in forum Networking
    Replies: 1
    Last Post: 12-20-2007, 10:18 AM
  5. send files through socket
    By bbq in forum Advanced Java
    Replies: 1
    Last Post: 06-05-2007, 02:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts