Hemmels
Hemmels

Reputation: 892

SocketException: Permission denied: connect

I was wondering in what other circumstances this (SocketException: Permission denied: connect) error would be thrown from the line

SocketAddress socketAddress = new InetSocketAddress("86.143.5.165", 6464);
// Set a 3s timeout
clientSocket.connect(socketAddress, 3000);

There are a few Android issues relating to permissions, and when using a port < 1024. I am running a simple java client/server app, on port 6464, and i am using java 1.6.0_32 (after reading that Java 1.7.0_7 adds ipv6 support).

I have port 80 forwarded to my server (verified on the client machine by going to my external IP in a browser), and the port 6464 is open also.

Why would the client be refused connection?

EDIT: I did originally get this error when trying to connect to the server from the server itself. (Obviously, I guess it's like a telephone in that you get an engaged tone). I had a friend test it, and he could connect. I'm now connecting from a laptop that isn't on the LAN (i.e. using a 3g mobile as a hotspot), but strangely still getting the error.

EDIT2:

java.net.SocketException: Permission denied: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at runtime.MyGame.main(MyGame.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javaws.Launcher.executeApplication(Unknown Source)
at com.sun.javaws.Launcher.executeMainClass(Unknown Source)
at com.sun.javaws.Launcher.doLaunchApp(Unknown Source)
at com.sun.javaws.Launcher.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
#### Java Web Start Error:
#### Socket failed to connect

Upvotes: 6

Views: 36207

Answers (5)

OldCurmudgeon
OldCurmudgeon

Reputation: 65869

For those landing here with a similar issue to mine.

I was getting this error while running Spock Groovy tests from Maven. Running the Groovy tests directly worked fine while running them from Maven failed.

To solve the problem configure the maven-surefire-plugin to never fork.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <forkMode>never</forkMode>
    </configuration>
</plugin>

Upvotes: 0

Nathan
Nathan

Reputation: 8971

I got this exception when disconnecting from Cisco AnyConnect VPN version 4.10.05111. The problem resolved the next time a connection was made.

Upvotes: 0

Hemmels
Hemmels

Reputation: 892

This is to do with very localised network settings on the client. Other clients can connect without issue, I'm thinking it could be to do with workgroups, or specific local client firewalls. Thanks all.

Upvotes: 0

user207421
user207421

Reputation: 311023

The client isn't being 'refused connection'. It is being refused permission to connect, by the local operating system.

IPv6 support was added in Java 1.4.

Upvotes: 2

VoidWhisperer
VoidWhisperer

Reputation: 73

Well, first of all, giving us 'MyIpAsAString' and the port would be useful. Anyways, are you sure for a fact that the serve program is running on that IP and port? That would be generally why, or that your code for taking the connection in in itself is not correct.

Upvotes: -1

Related Questions