LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 01-21-2005, 09:55 PM   #1
bobwall
Member
 
Registered: Jul 2004
Location: Milpitas, California
Distribution: 1/2 Debian 1/2 my own
Posts: 189

Rep: Reputation: 30
poor java socket read performance


Hello, I'm just learning network programming and I've made a test program that checks the latest versions of various software. I'm using the HTTPSession (reinvented the wheel on purpose) to retreive webpages, but the time it takes is excessive. I find that it would read a few hundred bytes, hang, read a some more until it's done. I ran this program under both Windows and Linux to see if was due to ip implementation differences, but in both cases, using BufferedReader to read a socket is much faster than GetPage. I also suspected that this problem could be because I'm using the latest Java Mustang releases. Any ideas what the problem is?


public class HTTPSession
{
HTTPSession()
{
}
void Open(String host_name) throws IOException
{
m_socket = new Socket(host_name, 80);
m_out = new PrintStream(m_socket.getOutputStream());
m_in = m_socket.getInputStream();
m_host_name = host_name;
}
String GetPage(String path) throws IOException
{
String string = "", s;
m_out.print("GET " + path + " HTTP/1.1\n" +
"Host: " + m_host_name + "\n\n");
m_out.flush();
byte buffer[] = new byte[8192];
int bytes_read;

while ((bytes_read = m_in.read(buffer)) != -1)
{
// fixme: this will not work for non ascii encoded web pages
// and very bad in terms of memory fragmentation
for (int i = 0; i < bytes_read; ++i)
string += (char)buffer[i];
}
return string;
}
String m_host_name;
private Socket m_socket;
private PrintStream m_out;
private InputStream m_in;
}
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
poor performance javabb Red Hat 8 01-20-2005 05:48 AM
poor performance in x ah786 Slackware 10 11-09-2004 11:11 AM
Poor performance Shyne Red Hat 1 10-17-2004 11:50 AM
Poor Video Performance yoink Linux - Newbie 3 12-03-2002 12:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 08:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration