Results 1 to 1 of 1
- 12-07-2012, 08:29 AM #1
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
access denied("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve")
Hi
I know probably you have seen this question being asked a million times and I have tried to follow all the suggested solutions with no luck. Below is my setup:
1. OS Windows 7
2. My server file: C:\soc\NetServer.class
3. Server Run at command prompt: C:\Soc>java -Djava.security.policy=socall NetServer
Server Started...
(no problem with server)
4:My client file: C:\Soc\NetApplet.class
5.My HTML file: C:\Soc\SocketTest.html
6.My policy file:C:\Soc\socall.policy
7. Tried running the appletviewer from command prompt and calling the html file from browser and in both instances get the same access denied error.
Command Line: c:\Soc>appletviewer -J-Djava.security.policy=socall C:\Soc\SocketTest.html
Internet Explorer: C:\Soc\SocketTest.html
Below are the code files:
Server:
Client:Java Code:[I][SIZE=1]import java.io.*; import java.net.*; import java.util.*; public class NetServer { public static void main(String[] args) { try { ServerSocket serverSocket = new ServerSocket(1099); System.out.println("Server Started..."); Socket clientSocket = serverSocket.accept(); BufferedReader fromClient = new BufferedReader( new InputStreamReader(clientSocket.getInputStream())); PrintWriter toClient = new PrintWriter(clientSocket.getOutputStream(), true); System.out.println("Server Started.."); while (true) { Integer numb = new Integer(fromClient.readLine()); System.out.println("received: " + numb.intValue()); toClient.println(numb.intValue()+1); } } catch(IOException ex) { System.err.println(ex); } } }[/SIZE][/I]
HTML File:Java Code:[SIZE=1] import java.applet.Applet; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; public class NetApplet extends Applet implements ActionListener { TextField numbField; Label display, errorMgs; Socket socket; public void init() { numbField = new TextField(6); this.add(numbField); Button button = new Button("Send"); this.add(button); button.addActionListener(this); errorMgs = new Label("Gip"); this.add(errorMgs); display = new Label("No number"); this.add(display); validate(); try { socket = new Socket("127.0.0.1",1099); } catch (UnknownHostException e) { errorMgs.setText( "Unknown host" + errorMgs.getText()); System.out.println("Unknown host"); } catch (IOException e) { errorMgs.setText("IO Exception" + e.getMessage() + errorMgs.getText()); System.out.println("IO Exception"); return; } } public void actionPerformed(ActionEvent e) { int numb = 0; String numbStr = null; BufferedReader fromServer = null; PrintWriter toServer = null; String actionCommand = e.getActionCommand(); if (e.getSource() instanceof Button) if (actionCommand.equals("Send")) { try { numb = Integer.parseInt(numbField.getText()); } catch (NumberFormatException ex) { System.out.println("Number Format Exception"); errorMgs.setText("Number Format Exception" + errorMgs.getText()); } try { fromServer = new BufferedReader( new InputStreamReader(socket.getInputStream())); toServer = new PrintWriter(socket.getOutputStream(), true); } catch (IOException ex) { System.out.println("IO Exception"); errorMgs.setText("IO Exception2" + errorMgs.getText()); } toServer.println(numb); try { numbStr = fromServer.readLine(); } catch (IOException ex) { System.out.println("Applet receive failed:"); errorMgs.setText("Applet receive failed:" + errorMgs.getText()); } display.setText(numbStr); } } } [/SIZE]
Policy file socall.policyJava Code:<HTML> <HEAD> <TITLE>Test</TITLE> </HEAD> <BODY> <P> <CENTER> <APPLET CODE="NetApplet.class" width="500" height="500"> </APPLET> </CENTER> </BODY> </HTML>
Java Code:/* AUTOMATICALLY GENERATED ON Fri Dec 07 01:26:39 EST 2012*/ /* DO NOT EDIT */ grant codeBase "file://C:\soc" { permission java.security.AllPermission; };
Similar Threads
-
Error: "Exception in thread "main" java.util.NoSuchElementException"
By Mattiscool in forum New To JavaReplies: 1Last Post: 11-02-2012, 11:38 PM -
Convert string operation symbols "+", "-", "/", "*" etc.
By Googol in forum New To JavaReplies: 3Last Post: 10-30-2012, 03:06 PM -
Got struck with this :- " Exception in thread "main" java.lang.NullPointerException"
By Vermont in forum New To JavaReplies: 5Last Post: 12-21-2011, 06:44 PM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks