1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Rep Power


    I am making a java chat and I get

    securityExeptionEx:cannot access ip : port

    ip and port are my ip and port

    here is code to connect client to the server
                socket = new Socket (host, Integer.parseInt (port));
                InputStream ii = socket.getInputStream ();
                OutputStream oo = socket.getOutputStream ();
                i = new DataInputStream (new BufferedInputStream (ii));
                o = new DataOutputStream (new BufferedOutputStream (oo));
                o.writeUTF (nameInput);
                o.flush ();
                Outputs.appendText ("Connection established...\n");
            catch (IOException ex)
                ex.printStackTrace ();
    and this is server code
    ServerSocket server = new ServerSocket(port);
                    while (true)
                            Socket client = server.accept();
                            System.out.println("Accepted from " + client.getInetAddress());
                            handler c = new handler(client);
                            System.out.println("Users connected: " + String.valueOf(c.handlers.size()+1));
    When I execute client.java in editor it connects and works fine but when I open client.html it gives that error
    Why does that happen and how to fix it?
    Thank you for any help.
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Lincoln, NE. USA
    Rep Power
    I assume you are trying to make an applet that does this? If so, applets can only connect to the "server" they were served from. I also further assume that you are not running an actual web server off your machine and are merely double clicking the html file to view it? I do not know what info the applet will have as its originating server when you just double click on it. This is probably the problem.

    If this is all true, as long as your server (the serversocket code) and the web server that serves your applet up are on the same box when deployed, my guess is that your code will work. If you do not have a web server handy, download apache and install it. They have a binary for windows that you can install fairly quickly. You should then be able to access the html file through a running apache on your machine and run the serversocket code and I bet it will work.

    Hope that all made sense and it helps. gl

IMN logo majestic logo threadwatch logo seochat tools logo