Results 1 to 7 of 7
Thread: Socket applet programming error?
- 05-28-2008, 05:37 AM #1
Member
- Join Date
- May 2008
- Posts
- 26
- Rep Power
- 0
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)
- 05-28-2008, 05:47 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I hope you don't have access privileges through the service. Any username password are not to be set. Is there such any?
- 05-28-2008, 05:57 AM #3
Member
- Join Date
- May 2008
- Posts
- 26
- Rep Power
- 0
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.
- 05-28-2008, 06:17 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I think it is,
Are you sure that through that port you can listen?Java Code:access denied (java.net.SocketPermission 127.0.0.1:4000 connect,resolve)
- 05-28-2008, 09:30 PM #5
Member
- Join Date
- May 2008
- Posts
- 26
- Rep Power
- 0
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:
It’s only from the web server that it can not seem to connect from. Here is the client code:Java Code:img294.imageshack.us/img294/1895/clipimage002wl1.jpg
I am also behind a route, do you think that can be the issue?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(); } } }
- 10-05-2011, 08:18 PM #6
Member
- Join Date
- May 2010
- Posts
- 23
- Rep Power
- 0
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. :(
- 10-05-2011, 09:15 PM #7
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,619
- Rep Power
- 5
Similar Threads
-
Socket programming - accepting files
By ravian in forum NetworkingReplies: 2Last Post: 11-29-2007, 10:40 AM -
Socket programming - port issues
By ravian in forum NetworkingReplies: 2Last Post: 11-07-2007, 10:24 AM -
Programming Socket Question
By paul in forum NetworkingReplies: 1Last Post: 07-30-2007, 07:26 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks