Results 1 to 3 of 3
- 11-30-2007, 08:15 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 1
- Rep Power
- 0
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.
- 03-13-2009, 07:36 PM #2
Member
- Join Date
- Mar 2009
- Posts
- 13
- Rep Power
- 0
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 transmissionLast edited by strati1991; 03-13-2009 at 07:39 PM.
- 03-14-2009, 07:39 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Similar Threads
-
send file via client - server model
By spasavvas in forum NetworkingReplies: 15Last Post: 08-13-2010, 11:45 AM -
send/read int in a client/server app
By dim_ath in forum New To JavaReplies: 2Last Post: 01-03-2008, 01:03 PM -
how to send .jar files client to server
By gobinathm in forum NetworkingReplies: 1Last Post: 12-25-2007, 04:05 AM -
Identify Client in Socket Client Server Application
By masadjie in forum NetworkingReplies: 1Last Post: 12-20-2007, 09:18 AM -
send files through socket
By bbq in forum Advanced JavaReplies: 1Last Post: 06-05-2007, 02:08 AM


LinkBack URL
About LinkBacks

Bookmarks