Applet socket connection

Hi,
I have an applet that connects to a server java console program through a socket connection which works fine from the command line using appletviewer but doesn't work when running in a html page. The applet is not signed however because the applet and server are running on the same machine it shouldn't need to be. I have used socket connections in applets before and have managed to make the connection to server without having it signed but this one is not working for some reason. I have checked the port is opened and again its the same one I have used before so I know its open.
I am getting the message java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:5000 connect,resolve) when calling:
  Socket s = new Socket(ip,port);I also have a java.policy.applet file in the project root directory which has the following in:
grant {
  permission java.security.AllPermission;
};Does anyone know a reason why access could be restricted?

Night.Monkey wrote:
Hi,
I have an applet that connects to a server java console program through a socket connection which works fine from the command line using appletviewer but doesn't work when running in a html page. The applet is not signed however because the applet and server are running on the same machine it shouldn't need to be.Wrong. An unsigned applet can only connect back to the server from where it was downloaded. Your applet comes from www.javawebgames.co.uk and tries to connect to 127.0.0.1.
Would your server be at www.javawebgames.co.uk there should be no problem.
I also have a java.policy.applet file in the project root directory which has the following in:
grant {
permission java.security.AllPermission;
};I think this should have zero effect when you are running in the actual browser.

Similar Messages

  • Applet socket connect behaves wrong.

    Hi,
    I have a very strange behavior from the Socket connect method. When i run the code attached as an applet the connect returns as if the connection is established (no machine on my network with the address 12.12.12.12 and ping to 12.12.12.12 fails as expected).
    When i run it from a command line (in a stadard main) the connect behaves as expected an i get an exception.
    Any ideas? what am i doing wrong? (or is it a known applet behavior???)
    thanks...
    ===========================================================
    the code:
    ===========================================================
    public void start() {
    SocketAddress sockaddr = new InetSocketAddress("12.12.12.12", 16000);
    Socket sock = new Socket();
    try {
    System.out.println("Start conn 1");
    sock.connect(sockaddr, 3000);
    } catch (IOException e) {
    System.out.println("Connect failed");
    e.printStackTrace();
    return;
    if (sock.isConnected()) {
    System.out.println("Connected");
    System.out.println("Connect succ 1");
    Edited by: ohad_atia on Jun 28, 2009 12:25 AM

    here is the applet start code - the rest of the methods are empty:
    (no exception here - that is the problem)
          public void start() {
              SocketAddress sockaddr = new InetSocketAddress("12.12.12.12", 16000);
                     Socket sock = new Socket();
              try {
                   System.out.println("Start conn 1");
                   sock.connect(sockaddr, 3000);
              } catch (IOException e) {
                   System.out.println("Connect failed");
                  e.printStackTrace();
                  return;
              if (sock.isConnected()) {
                 System.out.println("Connected");
              System.out.println("Connect succ 1");
          }the code and output i got when i run it using a command line:
    import java.net.Socket;
    import java.net.SocketAddress;
    import java.net.InetSocketAddress;
    import java.io.IOException;
    public class networktest {
            public static void main(String[] argv) {
                    SocketAddress sockaddr = new InetSocketAddress("12.12.12.12", 16000);
                    Socket sock = new Socket();
            try {
                    sock.connect(sockaddr, 3000);
                } catch (IOException e) {
                    System.out.println("Connect failed");
                    e.printStackTrace();
                    return;
                if (sock.isConnected()) {
                       System.out.println("Connected");
                System.out.print("Connect succ");
    }output:
    Connect failed
    java.net.SocketTimeoutException: connect timed out
    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 networktest.main(networktest.java:17)
    thanks for your help

  • Decompile applet and proxify all URL and socket connection and recompile

    Hi,
    Please anybody have idea for the below.
    I need to decomple the applet class file to .java file and need to change all URL and Socket connection to proxify all connections from applet. and recompile the sample applet to make ready to load in browser.
    Thi is to load the applet form the web server through one proxy server. In the proxy server side While loading the applet from web server that applet code need to be changed to modify the URL and connections used in that applet to change the further connection from applet through proxyserver.
    Compile and decompile is not a problem that i can use javac and javap respectively.
    But I want to know how to change all URL and connection in applet. is there any easy way to handle this with out changing the applet code.
    can Anybody help me.
    Thanks and Regards,
    Shiban.

    Not sure how you do that:
    Client <----[HTTPS]-----> Secure Gateway <------[HTTP]------->Web servers
    or
    Internet Explorer/Mozilla <----[HTTPS]-----> proxy <------[HTTP]-------> Google
    Is the above correct?
    If so than what are the proxy settings in IE/Moz, I can specify the proxy address in the
    browsers but not the proxy type (SSL).
    When you want to visit a page like google I gues you just type http://www.google.com in
    the browsers address bar. The browser will figure out how to connect to the proxy.
    Java has got the control panel in the general tabl there is a button "network settings...:"
    I have it to "use browser settings" and this works for me.
    All URL and URLConnections work but the sockets don't (maybe put in a bug report)
    for example games.yahoo.com -> card games -> bridge -> create table
    In the trace I can see:
    network: Connecting http://yog70.games.scd.yahoo.com/yog/y/b/us-t1.ldict with proxy=HTTP @ myproxy/00.00.00.00:80
    network: Connecting socket://yog70.games.scd.yahoo.com:11999 with proxy=DIRECT
    The second one fails because port 11999 is not open (what idiot uses an unassigned
    port for a profesional site is beyond me).
    http://www.iana.org/assignments/port-numbers
    #               11968-11999 Unassiged
    Even if the port was open on the proxy you'll notice with proxy=DIRECT that
    "use browser settings" does not work with socket (bug report??).
    Anyway my advice is to open the java console (windows control panel or javacpl.exe in
    the bin dir of java.home) and make sure it is set to "use browser settings"
    Then enable a full trace:
    To turn the full trace on (windows) you can start the java console, to be found here:
    C:\Program Files\Java\j2re1.4...\bin\jpicpl32.exe
    In the advanced tab you can fill in something for runtime parameters fill in this:
    -Djavaplugin.trace=true -Djavaplugin.trace.option=basic|net|security|ext|liveconnect
    if you cannot start the java console check here:
    C:\Documents and Settings\userName\Application Data\Sun\Java\Deployment\deployment.properties
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    add or change the following line:
    javaplugin.jre.params=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    for 1.5:
    deployment.javapi.jre.1.5.0.args=-Djavaplugin.trace\=true -Djavaplugin.trace.option\=basic|net|security|ext|liveconnect
    The trace is here:
    C:\Documents and Settings\your user\Application Data\Sun\Java\Deployment\log\plugin...log
    I think for linux this is somewhere in youruserdir/java (hidden directory)
    Print out the full trace of the exception:
    try{...}catch(Exception e){e.printStackTrace();}
    Then visit the games.yahoo and try to create a new table playing bridge.
    Inspect the trace and see if it works/why it doesn't work.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Establish socket connection with local pc using Applet

    Hi,
    I want to write an applet embedded in my web application.
    When I access the web application from my PC which is connected to a RFID reader, I need the applet to make a socket connection to the attached RFID reader.
    Is this allow?
    If not, what do I need to make this possible for applet?
    Please advise.
    Thank you.

    HI Helen,
    Just to check.
    He is on XP ?
    He is using AIM 5.9 ?
    He has Tuned the camera and Mic to the App ?
    If he is at Service Pack 2 he has enabled the app through the XP firewall ?
    You have the MAc firewall Off.
    The ports are enabled in your modem.
    Either using UPnP or these actual ports
    5060, 5190, 5678, 16384-16403 for just the AIM stuff.
    Have you changed the Quicktime setting to match your download speed ?
    Can you and he get any of the people or test accounts o this page ?
    http://www.ralphjohnsuk.dsl.pipex.com/ContactTesters.html
    2:34 PM Saturday; April 8, 2006

  • Socket connection in Applet

    Hi champ,
    I created an server and client chat applet. when i execute server and client application it works fine. but when i use applet for client it throws IONetPermission denied error. I know i have to do some thing in policies. But i cannot do in client machine. So is there any other way to handle. adn i know that it is possible because i have seen few chat which use socket connection and yet client has to do nothing with policy. So there must be some thing to do in server machine. Please help me to find the process that i have to follow in server machine to run this client applet without any error.
    Thanks in advance.
    Nischal

    Security model for the applets doesn't allow you to connect to hosts other then host where you download applet code. To go through that limit you have to sign your applet code or provide a proxy on your web site hosting a applet.
    The good starting point for a code signing and applet security is a http://home.istar.ca/~neutron/java.html

  • Applet using socket connection always go through proxy server

    Socket connection with socks always go through proxy server
    We have two applets in different codebases using socket to talk to each other, until now nothing new, but the problem is that we are behind a proxy server with socks and because of that, the connection always go through the proxy server even with proxy override point to the applet machine. We have tried a lof of things and until now nothing worked, it looks like the socket is ignoring proxy override configuration. We would like to know if there is a way to solve this problem making the applets comunicate to each other ignoring the proxy server. It should happen when we set the plug-in option to "no proxy host", but it doesn't. Maybe it can be a bug of JVM, I don't know, just maybe, and if it's true, any other good idea would be welcome as well.
    Thanks in advance.

    Hi,
    I am not very much sure if I can help you. In my previous experience, once you set the system property to use the proxy, then the jvm uses the proxy. If you want disable, in your code, you have to disable it.
    like System.setProperty("socksProxyHost","someHost"), Properties props = System.getProperties(); props.remove(("socksProxyHost");

  • Applet socket problem in client-server, urgent!

    Dear All:
    I have implemented a client server teamwork environment. I have managered to get the server running fine. The server is responsible for passing messages between clients and accessing Oracle database using JDBC. The client is a Java Applet. The code is like the following. The problem is when I try to register the client, the socket connection get java.security.AccessControlException: access denied(java.net.SocketPermission mugca.its.monash.edu.
    au resolve)
    However, I have written a Java application with the same socket connection method to connect to the same server, it connects to the server without any problem. Is it because of the applet security problem? How should I solve it? Very appreciate for any ideas.
    public class User extends java.applet.Applet implements ActionListener, ItemListener
    public void init()
    Authentication auth = new Authentication((Frame)anchorpoint);
    if(auth.getConnectionStreams() != null) {
    ConnectionStreams server_conn = auth.getConnectionStreams();
    // Authenticates the user and establishes a connection to the server
    class Authentication extends Dialog implements ActionListener, KeyListener {
    // Object holding information relevant to the server connection
    ConnectionStreams server_conn;
    final static int port = 6012;
    // Authenticates the user and establishes connection to the server
    public Authentication(Frame parent) {
    // call the class Dialog's constructor
    super(parent, "User Authentication", true);
    setLocation(parent.getSize().width/3, parent.getSize().height/2);
    setupDialog();
    // sets up the components of the dialog box
    private void setupDialog() {
    // create and set the layout manager
    //Create a username text field here
    //Create a password text field here
    //Create a OK button here
    public void actionPerformed(ActionEvent e) {
    authenticateUser();
    dispose();
    // returns the ConnectionStreams object
    public ConnectionStreams getConnectionStreams() {
    return(server_conn);
    // authenticates the user
    private void authenticateUser() {
    Socket socket;
    InetAddress address;
    try {
    // open socket to server
    System.out.println("Ready to connect to server on: " + port);
    socket = new Socket("mugca.its.monash.edu.au", port);
    address = socket.getInetAddress();
    System.out.println("The hostname,address,hostaddress,localhost is:" + address.getHostName() + ";\n" +
    address.getAddress() + ";\n" +
    address.getHostAddress() + ";\n" +
    address.getLocalHost());
    catch(Exception e) {
    displayMessage("Error occured. See console");
    System.err.println(e);
                                  e.printStackTrace();
    }

    Hi, there:
    Thanks for the help. But I don't have to configure the security policy. Instead, inspired by a message in this forum, I simply upload the applet to the HTTP server (mugca.its.monash.edu.au) where my won server is running. Then the applet is download from the server and running fine in my local machine.
    Dengsheng

  • Servlet/applet/socket problem

    Hi there,
    my problem is this...
    i create a page with an servlet whicht shows an applet. this applet connects to a server through an socket. it works fine, but, when i change the page and the applet is not longer on the screen, the socket connection will be not killed! i dont know why. but i must kill it when the applet is not longer on the screen...whats wrong? can you help me?
    matthias

    Are you overriding the destroy() method in your Applet? This will be called when the applet is about to be unloaded from the browser. Or, as a slightly different alternative, you can override the stop() method, which is called when the applet is scrolled off the screen. Usually when stop() is used, start() is overriden as well to allow the applet to resume when it is scrolled back into view. For more info, read up on the applet lifecycle.

  • Help with an exception when trying to establish a socket connection

    i am trying to make a chat (using an applet for the client).......
    it uses an simple socket connection between the server and clients.....when i connect the client to address 127.0.0.1 or localhost everything works fine, but when i try to connect the client to my DNS name or ip, i get an exception....the exception reads:
    java.security.AccessControlException: access denied (java.net.SocketPermission nextwave.dyndns.org resolve)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
    at java.security.AccessController.checkPermission(AccessController.java:401)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
    at java.lang.SecurityManager.checkConnect(SecurityManager.java:1042)
    at java.net.InetAddress.getAllByName0(InetAddress.java:937)
    at java.net.InetAddress.getAllByName0(InetAddress.java:918)
    at java.net.InetAddress.getAllByName(InetAddress.java:912)
    at java.net.InetAddress.getByName(InetAddress.java:832)
    at java.net.InetSocketAddress.<init>(InetSocketAddress.java:109)
    at java.net.Socket.<init>(Socket.java:119)
    at Client.<init>(Client.java:42)
    at ClientApplet.init(ClientApplet.java:12)
    at sun.applet.AppletPanel.run(AppletPanel.java:347)
    at java.lang.Thread.run(Thread.java:536)
    what is this all about??????
    i'm not that fluent in java, or networking at that, but i'm sure there is something i can do to fix this......
    any help would be greatley appreciated.

    this is why i am not heart-broken that i will be going the other (executable jar) route.......the major deciding factor is the people who will be using this chat will most likley not be able to edit the policy file due to lack of knowledge, and probably won't want to take the time to try.....they would rather download a program, and double-click execute........
    i thank you for taking the time to help me......i have been reading through the posts in this forum, and am seeing it is a good place to get help, so i will be sticking around.....
    mahalo and happy java

  • Applet Servlet Connection

    Hi,
    I am trying to develop a chatroom application. I am using a applet as client which communicates with a servlet by recieving and sending a serialized object.
    This is done by using the URLConnection class.
    If one user send a message to the servlet then the servlet needs to send that message to all user in the chatroom.
    Herefore I need the connections to each applet. I need to store each connection to the applet of the user.
    How can implement this?
    Thanks

    Maybe you should open a socket connection from the applet to the servlet instead of using URLConnection. There is a tutorial on sockets on the java.sun.com site.

  • Is there any way to make a socket connection to a java file on the net?

    Is their anyway to make a socket connection to a java applet that I place on a webhost? I want to connect to a javaapplet from my vb.net program and send commands to it. Like http://www.geocities.com/Sylonious/javafile.jpx:7070
    ?

    Is their anyway to make a socket connection to a java
    applet that I place on a webhost? I want to connect to
    a javaapplet from my vb.net program and send commands
    to it. Like
    http://www.geocities.com/Sylonious/javafile.jpx:7070
    ?You wouldn't have a port in the url, you would need to have the socket open in the applet code. The vb.net program would also need to be on the same server as the applet or you'll have security issues and I doubt that's possible with geocities. I don't know what you would need to communicate with a vb.net if anything, but I'm sure it's possible.

  • Can a socket connection be created inside a Timeline to port 23?

    Is there a security restriction or some other reason why I always get a java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method)
    when I try to open a socket inside a function in a Timeline to port 23? The connection works fine to the host if the code is not is not inside a Timeline. It also seems that a socket connection to port 80 works okay too.
    Thanks for any help in advance.
    Regards,
    Richard

    Here is the Timeline code:
    var addr:InetSocketAddress;
    var sConn:Socket;
    var reader:BufferedReader;
    var s:String;
    Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
    KeyFrame {
    time: 10s
    action: function() {
    try {
    addr = new InetSocketAddress("somehost",23);
    sConn = new Socket();
    sConn.connect(addr);
    reader = new BufferedReader(
    new InputStreamReader(sConn.getInputStream()));
    // reader.readLine(); // throw away first line
    s = reader.readLine();
    bindTemp = response.getResponse("$0001").getTemperature();
    bindVolt = response.getResponse("$0001").getVoltage();
    } catch (e:Exception) {
    System.err.println(e);
    }.play();
    The ConnectionRefused error occurs only when the NetBeans Project Application Properties "Draggable Applet" checkbox is checked ( which is the default ). Once I uncheck it, the error goes away.
    -Richard

  • Applet security connecting to hosts

    it is said that unsigned applets cannot connect to hosts other than the origin host.
    - By origin host, is it the host from where the html is downloaded or the host from where the jar file is downloaded?
    - should the applet be connecting using the exact hostname or its ip address can also be used?
    - signed applet doesnt have any of these restrictions right?
    - are there any restrictions on connecting to hosts using appletcontext.showDocument? I guess no - because the page is opened in the browser and available to the applet directly. is this correct for both signed and unsigned appelts? Indirectly the data is available to the applet through live connect, what say?
    Thanks.

    - By origin host, is it the host from where the html is downloaded or the host from where
    the jar file is downloaded?
    The codebase of the applet, use this.getCodeBase() to get an URL object to cennect,
    for a Socket you can use the URL object .getHost and getPort to create a Socket
    allthough a socket doesn't use the browser's settings to make a connection and you
    can have problems when the client uses a proxy or https.
    - should the applet be connecting using the exact hostname or its ip address can also
    be used?
    I think it doesn't really matter but am not sure, use getCodeBase instead of hard
    coding the host .
    - signed applet doesnt have any of these restrictions right?
    Correct, if the user trusts the applet. The user will be asked if he or she trusts the
    applet.
    - are there any restrictions on connecting to hosts using
    appletcontext.showDocument? I guess no - because the page is opened in the
    browser and available to the applet directly. is this correct for both signed and
    unsigned appelts? Indirectly the data is available to the applet through live connect,
    what say?
    appletcontext.showDocument will open a new browser window, don't think there is
    any restrictions in that except that Moz will activate the popup stopper.

  • Socket connect slow in JDK 1.5?

    We recently began testing our Java Swing application with JDK 1.5, and we noticed that socket.connect()
    calls are taking several seconds to return, when before in 1.4 the calls returned immediately.
    Here is some sample code:
    Socket sock = new Socket();
    InetSocketAddress sockAddr = new InetSocketAddress(inAddress, portNum);
    sock.connect(sockAddr, 2000);
    What could be wrong? I've debugged the code and verified inAddress is an IP address,
    not a hostname.
    -Eric

    Here is the list of enhancements in JDK1.5.
    http://java.sun.com/j2se/1.5.0/docs/guide/net/enhancements-1.5.0.html
    I wonder if any of them are having some effect in the slow connection.
    There are some network properties that you can tweak with. Did you try them?
    Here is the list
    http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html

  • Is there any way to identify the particular socket connection is closed ?

    Is there any way to identify the particular socket connection is closed or not ?
    Any methods ???
    How can the program knows the connection is lost or some thing ...
    Is the socket throws some excpetions when there is no active connection ???
    namanc

    If you get an IOException when you try to use the socket, the connection was obviously closed.
    The correct way for an application to know if the socket was closed is:
    1) the server sends a message indicating that the socket should be closed
    2) the client closes the socket itself

Maybe you are looking for