Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Faster bufferedInputStream, is it possible?

Posted on 1998-08-03
7
340 Views
Last Modified: 2010-04-16
Hello.

I have a problem with bufferedinputstream, is there a way to speed it up.
So i can read faster from the bufferedinputstream?

Pierre Andersson
0
Comment
Question by:pierre_andersson
  • 4
  • 3
7 Comments
 
LVL 6

Expert Comment

by:gadio
ID: 1230724
What seems to be the problem with the bufferedinputstream's speed? Can you attach a code that shows the problem?
0
 

Author Comment

by:pierre_andersson
ID: 1230725
The problem is as follow:

I have a buffer with 200000 bytes and a bufferedinputstream connected to a server over a socket. When the server is sending really fast(1 String/ 1/2 second) the buffer(byte[200000]) is filled with strings and the time for the string to be shown in the client window is incresing.

Pierre Andersson.
0
 
LVL 6

Expert Comment

by:gadio
ID: 1230726
Pierre, could it be that you are displaying all the data in the buffer each time you display? That would explain the fact that the display time is increasing. Why don't you work with smaller buffers? It would be much more efficient.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:pierre_andersson
ID: 1230727
Thanks for your answer!!!

The problem is that i don't really know how big the buffer must be, because the server must serve 4000 clients and broadcast all the message to all the clients each time the server is receiving a message. I don't think that alla the clients will send a message at the same time but i want the server and client to be as fastest they can. Do you know what size the buffer should be.

Thanks for your help.

Pierre Andersson.
0
 
LVL 6

Accepted Solution

by:
gadio earned 100 total points
ID: 1230728
Pierre, when you read and write to sockets you are I/O bound, that is, the cpu is idle most of the time waiting for the communication to happen. I suggest that you try a different approach. If your messages are delimited by newline, try to use

// the input stream from the client socket is inpstr
BufferedReader br = BufferedReader(new InputStreamReader( inpstr ) );
while( /*condition*/ ) {
   String msg = br.readLine();
   if( /* msg is relevant to me */ ) {
      // Handle message
   }
}

If on the other hand, the message is delimited by some other characters, use the StreamTokenizer to break the stream to messages.

0
 

Author Comment

by:pierre_andersson
ID: 1230729
I am using $ to delimite the strings and StringTokenzier, is StringTokenizer ok, or should i use StreamTokenizer.

Pierre Andersson
0
 
LVL 6

Expert Comment

by:gadio
ID: 1230730
Use StreamTokenizer, mark all the characters that can be a part of a message as normal (including spaces), and the $ as whiteSpaceChars.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Opening PDF on button click and fill new document 2 47
expectj telnet failing 5 45
Desingning Refactoring existing code 2 26
Html Table Looping (part 2) 5 27
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question