Can't open socket to localhost

M

Mark McKay

I'm trying to set up a simple client/server pair of programs using
sockets, but am finding I can't establish a connection to the server
running on my localhost. When I execute:

InetAddress[] ia = InetAddress.getAllByName("localhost");
Socket sock = new Socket(ia[0], 8185);

I receive:

java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:8185 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
at java.security.AccessController.checkPermission(AccessController.java:401)

What can I do to test my programs?

Mark McKay
 
W

winbatch

Check your java.security file and make sure to give yourself the correct
permissions for socket connections.

Mark McKay said:
I'm trying to set up a simple client/server pair of programs using
sockets, but am finding I can't establish a connection to the server
running on my localhost. When I execute:

InetAddress[] ia = InetAddress.getAllByName("localhost");
Socket sock = new Socket(ia[0], 8185);

I receive:

java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:8185 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java
:269)
java.security.AccessController.checkPermission(AccessController.java:401)

What can I do to test my programs?

Mark McKay
 
T

Tor Iver Wilhelmsen

java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:8185 connect,resolve)

Do you use an applet loaded from another machine than localhost?
 
M

Mark McKay

Tor Iver Wilhelmsen said:
Do you use an applet loaded from another machine than localhost?

No, they're both running on localhost. Eventually I'd like to have my
server running on a remote machine and my web applet to be downloaded
from that machine and connect back to the server. Is there a way to
do this without requiring my users to modify java.security?

Mark McKay
 
J

John C. Bollinger

Mark said:
No, they're both running on localhost. Eventually I'd like to have my
server running on a remote machine and my web applet to be downloaded
from that machine and connect back to the server. Is there a way to
do this without requiring my users to modify java.security?

The server from which the applet is loaded is the _only_ system to which
it can make a network connection without modification of the client's
security policy. It is possible that that is in fact related to the
problem you are experiencing -- normally applets are forbidden from
accessing most resources on the client machine, so it may be that your
VM is applying that restriction without noticing that the applet came
from the same machine.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top