Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-30-2007, 09:15 PM
Member
 
Join Date: Nov 2007
Posts: 1
Rep Power: 0
Hinty is on a distinguished road
Default Server socket - send image to client
Hey,

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()];
fis.read(buffer);
ObjectOutputStream oos = new ObjectOutputStream(serverSocket.getOutputStream()) ;
oos.writeObject(buffer);

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

if you need anything else explain or more info please let me know.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 03-13-2009, 08:36 PM
Member
 
Join Date: Mar 2009
Posts: 13
Rep Power: 0
strati1991 is on a distinguished road
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");
fos.write(buffer);

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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 03-14-2009, 08:39 AM
Senior Member
 
Join Date: Jan 2009
Posts: 354
Rep Power: 2
toadaly is on a distinguished road
Default
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.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
send file via client - server model spasavvas Networking 13 12-02-2009 09:54 AM
send/read int in a client/server app dim_ath New To Java 2 01-03-2008 02:03 PM
how to send .jar files client to server gobinathm Networking 1 12-25-2007 05:05 AM
Identify Client in Socket Client Server Application masadjie Networking 1 12-20-2007 10:18 AM
send files through socket bbq Advanced Java 1 06-05-2007 03:08 AM


All times are GMT +2. The time now is 12:18 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org