Results 1 to 7 of 7
  1. #1
    Master Zero is offline Member
    Join Date
    May 2008
    Posts
    26
    Rep Power
    0

    Default Socket applet programming error?

    Hello,

    I have an applet which when run from eclipse works fine, but on my web server gives me an error. I am not sure what the error means, but could it be permission relate? If so then how do I set the proper permissions? Hereís the error, if my class code is needed, then I will provide it as well.

    Java Code:
    Java Plug-in 1.6.0_03
    Using JRE version 1.6.0_03 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Admin
    
    
    ----------------------------------------------------
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    p:   reload proxy configuration
    q:   hide console
    r:   reload policy configuration
    s:   dump system and deployment properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    ----------------------------------------------------
    
    Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:4000 connect,resolve)
    	at java.security.AccessControlContext.checkPermission(Unknown Source)
    	at java.security.AccessController.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkPermission(Unknown Source)
    	at java.lang.SecurityManager.checkConnect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.connect(Unknown Source)
    	at java.net.Socket.<init>(Unknown Source)
    	at java.net.Socket.<init>(Unknown Source)
    	at ChatClient.actionPerformed(ChatClient.java:74)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I hope you don't have access privileges through the service. Any username password are not to be set. Is there such any?

  3. #3
    Master Zero is offline Member
    Join Date
    May 2008
    Posts
    26
    Rep Power
    0

    Default

    Hi,

    The server is a java application (well jar file) listening for a client to connect. It works well from eclipse (the applet), but not on my web server. As far as I know, there arenít any username and passwords involved.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I think it is,

    Java Code:
    access denied (java.net.SocketPermission 127.0.0.1:4000 connect,resolve)
    Are you sure that through that port you can listen?

  5. #5
    Master Zero is offline Member
    Join Date
    May 2008
    Posts
    26
    Rep Power
    0

    Default

    Yes I am positive because when the client runs locally, it connects fine to the server. Here is proof of it running locally, the link below is a screenshot of it:

    Java Code:
    img294.imageshack.us/img294/1895/clipimage002wl1.jpg
    Itís only from the web server that it can not seem to connect from. Here is the client code:

    Java Code:
    import java.io.*;
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    import javax.swing.text.*;
    
    import java.awt.event.*;
    import java.applet.Applet;
    
    public class ChatClient extends Applet implements ActionListener {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	// Variables
    	TextField msg;
    	TextArea room;
    	
    	Style color;
    	StyledDocument doc;
    	
    	Panel cPanel;
    		JLabel lblIP;
    		JTextField IP;
    		JButton connect;
    	
    	PrintStream os;
    	DataInputStream is;
    	Socket clientSocket;
    	
    	public void init() {
    		this.setLayout(new BorderLayout());
    		
    		msg = new TextField();
    		room = new TextArea("", 5, 50, TextArea.SCROLLBARS_VERTICAL_ONLY);
    	
    		cPanel = new Panel();
    			lblIP = new JLabel("IP Address:");
    			IP = new JTextField("127.0.0.1");
    				IP.setHorizontalAlignment(JTextField.CENTER);
    			connect = new JButton("Connect");
    				connect.addActionListener(this);
    		cPanel.setLayout(new BorderLayout());
    		cPanel.add("Center", IP);
    		cPanel.add("West", lblIP);
    		cPanel.add("East", connect);
    		
    		this.add("South", msg);
    		this.add("Center", room);
    		this.add("North", cPanel);
    	}
    
    	// Sends the text
    	public void sendText(String message) {
    		os.println(message);
    		os.flush();
    	}
    	
    	// AWT event handler
    	@SuppressWarnings("deprecation")
    	public boolean keyDown(Event evt, int key) {
    		//System.out.println(key);
    		if (key == 10) {
    			room.append(msg.getText() + "\n");
    			this.sendText(msg.getText());
    			msg.setText("");
    			//return true; // ignores the key
    		} return super.keyDown(evt, key);
    	}
    	
    	public void actionPerformed(ActionEvent e) {
    		if (e.toString().split(",")[1].substring(4).equals("Connect")) {
    			try {
    				this.clientSocket = new Socket(IP.getText(), 4000);
    				os = new PrintStream(this.clientSocket.getOutputStream());
    				is = new DataInputStream(this.clientSocket.getInputStream());
    				
    				room.append("Connection successful...\n");
    				
    				Listen listen = new Listen();
    				new Thread(listen).start();
    			} catch (UnknownHostException e1) {
    				// TODO Auto-generated catch block
    				e1.printStackTrace();
    				room.append(e1.getMessage());
    				System.exit(0);
    			} catch (IOException e2) {
    				// TODO Auto-generated catch block
    				e2.printStackTrace();
    				room.append(e2.getMessage());
    				System.exit(0);
    			}
    		}
    	}
    	
    	// This class will be used to implement threading
    	public class Listen implements Runnable {
    		@SuppressWarnings("deprecation")
    		public void run(){
    			try {
    				room.append("Server --> " + is.readLine() + "\n");
    			} catch (IOException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    				room.append(e.getMessage());
    				System.exit(0);
    			}
    			
    			run();
    		}
    	}
    }
    I am also behind a route, do you think that can be the issue?

  6. #6
    oontvoo is offline Member
    Join Date
    May 2010
    Posts
    23
    Rep Power
    0

    Default Re: Socket applet programming error?

    The error you've been getting has to do with the Security Issue.
    For more details, see Appendix A: Security and Permissions

    Basically, what they are saying is that, your Applet is trying to access to your local resource, and that is simply prohibited. In order for you applet to get pass the socalled - "security check", you need to have some kind of "certificate", which I'm not very clear about.

    Hope this help,



    P.S: I was getting the same problem when I tried to embed a simple chat applet to my html page. :(

  7. #7
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Socket applet programming error?

    oontvoo...for what its worth, check the date of the original post - it is over 3 years old. I presume the original poster has fixed the problem or moved on (but...you never know)

Similar Threads

  1. Socket programming - accepting files
    By ravian in forum Networking
    Replies: 2
    Last Post: 11-29-2007, 10:40 AM
  2. Socket programming - port issues
    By ravian in forum Networking
    Replies: 2
    Last Post: 11-07-2007, 10:24 AM
  3. Programming Socket Question
    By paul in forum Networking
    Replies: 1
    Last Post: 07-30-2007, 07:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •