File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes connection refused to SocketServer when started from junit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "connection refused to SocketServer when started from junit" Watch "connection refused to SocketServer when started from junit" New topic
Author

connection refused to SocketServer when started from junit

Sigrid Kajdan
Ranch Hand

Joined: Jan 14, 2007
Posts: 72
Hi all,

I have a strange problem connecting to my socket server in junit tests started from Eclipse.
On the one hand, it works fine when I

a) start the Server from Eclipse or
b) start on the command line with command



On the other hand, I get Connection refused when I

c) start the server programmatically, calling
in a junit test class, either in before() or in beforeClass();

d) try to execute a system command, also in before() or beforeClass(), like



It seems obvious somehow that it has to do with junit somehow, but i don't know how...

In every case, I get the same output from netstat -a, so no matter how I start the server it's really listening:



Do you have an idea what's the problem here? Any ideas or hints would be very much appreciated...

Thank you
Sigrid
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
It seems in all cases you can see it is really listening ?

When you do it programmatically, are you sure you're not executing the code multiple time ?

Sorry, that's all I could come up with..

Besides that.. the "root" or "working directory" might not be the same.. I'm just thinking out loud, in case it makes you think of something else..

Regards,
Alex
Sigrid Kajdan
Ranch Hand

Joined: Jan 14, 2007
Posts: 72
Hi Alex,

thanks for your answer. I experimented a bit now, there are several issues:

1) First, I have to add a Thread.sleep after starting the server, otherwise the clients come asking too early :-)

2) After this change, I have it working now for a normal, direct programmatical start of the Server in beforeClass, but with my code for the indirect execution



it does not work, so there must either be something wrong in the code or it's a problem that a new process is started by Runtime (I'm not really an expert in this...)

Anyway, I have a working version now, so no problem :-)
Ciao
Sigrid
 
jQuery in Action, 2nd edition
 
subject: connection refused to SocketServer when started from junit
 
Similar Threads
Multi-threaded RMI server
B&S: Need some clarification on the single mode flag
Problem with JUnit integration in Eclipse
B&S Stub errors running in network client mode
Tomcat 404 - error