Solved

slow socket connection

Posted on 2006-11-29
10
390 Views
Last Modified: 2008-02-01
I would like to create a TCP/IP connection to a scales in the local network.
In Java 1.5 it takes 4-5 seconds while telnet can build up the connection immediately.
What can be wrong?

My code is the following:

long time = System.currentTimeMillis();
InetAddress addr = InetAddress.getByName("192.168.0.20");
System.out.println(System.currentTimeMillis() - time);
// running time: 90 ms

time = System.currentTimeMillis();
Socket socket = new Socket(addr, 8000);
System.out.println(System.currentTimeMillis() - time);
// running time: 4617 ms

How can it be made faster?

Thanks, Peter
0
Comment
Question by:pallosp
  • 4
  • 3
  • 3
10 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 18042853
looks like some systematic issue, can you post the strace result on the java program.

If you are running your program like this:

java Client

to capture system call trace, run as

strace java Client
and post the results.
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 18043622
When you create a socket it has to go through some security issues in order to see if the socket is allowed a connection to the specified host and port. This might be the problem. I suggest you do a few things.

a) Try the following in the command line: java -Djava.net.preferIPv4Stack=true <your programme> It is possible that if your operating system supports IPv6 Java may be trying to use this and if it fails then Java tries IPv4. Try forcing Java to use only IPv4.
b) Try your programme with earlier versions of java and see if you get the same results.
c) Try your programme with different computers and operating systems. It might be an os-specific problem.
0
 
LVL 9

Author Comment

by:pallosp
ID: 18043634
Is it a Linux command? I don't find it in jdk 1.5.0_09.
I'm currently developing in Windows XP although finally the application will be deployed on a Linux server.
0
 
LVL 35

Expert Comment

by:girionis
ID: 18043682
No, it is a property that you pass dynamically in the JVM.

java -Djava.net.preferIPv4Stack=true <your application>
0
 
LVL 9

Author Comment

by:pallosp
ID: 18043712
I thought of strace. While I was writing my comment Ajay-Singh's was the only answer.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 35

Expert Comment

by:girionis
ID: 18043730
I think he probably meant trace.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 18043920
I mean strace  - unix commands that prints system calls made by the application and their timings.
0
 
LVL 9

Author Comment

by:pallosp
ID: 18053939
Finally I could localize the error. The socket connection is slow only in JRockit JVM. After updating to BEA JRockit(R) JDK 5.0 Update 6 (R26.3.0-32) its speed became tolerable, although DNS name resolution is still 4 times, and building up the connection is 2 times slower than in Sun JVM. The -Djava.net.preferIPv4Stack=true option doesn't have effect on speed.

I uploaded the strace.log at http://www.novekdm.hu/strace.log if you're interested in.
0
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 18054275
> I uploaded the strace.log at http://www.novekdm.hu/strace.log if you're interested in.

I am not able to access this site.
0
 
LVL 9

Author Comment

by:pallosp
ID: 18056490
I don't know why you can't download the log, anyway here is another copy:
http://pallosp.fw.hu/strace.log
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PDFBox - convert image to PDF, PDF resolution 3 119
VB Script to add site to Java Exception List 4 53
couple of eclipse 5 27
fibonacci ten numbers 4 30
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

862 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now