File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes TCP Socket Creation Failure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "TCP Socket Creation Failure" Watch "TCP Socket Creation Failure" New topic

TCP Socket Creation Failure

Alex Kirk
Ranch Hand

Joined: Aug 13, 2001
Posts: 44
Using the Socket mySock = new Socket("my.ip.add.ress", port#) construct, I'm unable to create a connection on my local machine; I get a "connection refused" error.
At first, I thought this was an OS issue; I run OpenBSD, and they're notoriously paranoid about security. However, the folks at have basically assured me that the OS is not the issue, and they're backed up by the fact that I can call Python to do basically the same thing without any trouble.
I've had it suggested to me that Java is setting up the kernel call wrong, and that's the only plausible thing I can think of -- particularly since I have upgraded my kernel sine I installed my Java compiler (BTW, I run JDK 1.1.8).
Is there any testing I can to do see what the cause of the problem might be? Any ideas as to what might be going wrong?
Alex Kirk
Sean MacLean
Ranch Hand

Joined: Nov 07, 2000
Posts: 621
It's seems to me that either your socket address or port are wrong, the server you're trying to connect to isn't listening for connections, or (and this may be the culpret) the JVM permission aren't set to allow connections. To do this last one, create a text file (let's call it myPermissions)in the same directory as you server (I assume you're using a custom java server) containing this
grant {
permission "*:1024-65535",
permission "*:80", "connect";
Now, start the server by including the -D flag to set the security policy for the server.
java MyServer
This may solve you problem.
Alex Kirk
Ranch Hand

Joined: Aug 13, 2001
Posts: 44
Except for the fact that I'm not using a custom server, or anything like that. It's just a filesharing client program, nothing special. You can see my source at:
The file with the call in question is
Thanks for actually replying.
I agree. Here's the link:
subject: TCP Socket Creation Failure
It's not a secret anymore!