Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problems with security???

5 views
Skip to first unread message

dush

unread,
May 9, 2001, 9:08:31 AM5/9/01
to
hi all

Well I am trying to make a simple chat program with no rooms and
stuff. I got under way wiht some pervious help but now I have built a
sever and client and the thing won't work. I get the following runtime
error message

java.security.AccessControlException: access denied
(java.net.SocketPermission 127.0.0.1:8001 connect,resolve)
at
java.security.AccessControlContext.checkPermission(AccessControlContext.java:272)
at
java.security.AccessController.checkPermission(AccessController.java:399)
at
java.lang.SecurityManager.checkPermission(SecurityManager.java:545)
at
java.lang.SecurityManager.checkConnect(SecurityManager.java:1044)
at java.net.Socket.<init>(Socket.java:262)
at java.net.Socket.<init>(Socket.java:100)
at ChatClient.<init>(ChatApplet.java:99)
at ChatApplet.init(ChatApplet.java:22)
at sun.applet.AppletPanel.run(AppletPanel.java:344)
at java.lang.Thread.run(Thread.java:484)

I will also say that I installed IIS on my computer so I can test the
web page where my applet shoud be.

I will also list the code for the server and the applet:

server:
_____________________
import java.io.*;
import java.net.*;
import java.util.*;

public class ChatServer {

public static void main(String args[]) {
if (args.length > 0) {
Server cs = new Server(Integer.parseInt(args[0]));
cs.start();
}
else {
System.out.println("No port given!");
System.exit(0);
}
}
}

class Server extends Thread {
private Hashtable outputStreams = new Hashtable();
private ServerSocket ss;
private Socket s;

public PrintWriter out;

public Server(int port) {
try {
ss = new ServerSocket(port);
}
catch (Exception e) {
System.out.println("Error creating server socket:" + e);
}
}

public void run() {
while(true) {
try {
s = ss.accept();
out = new PrintWriter(s.getOutputStream());
outputStreams.put(s, out);
ConnectionThread ct = new ConnectionThread(s,out);
ct.start();
// out.println("Server says hi!");
}
catch (Exception e) {
System.out.println("Error while creating socket:" +
e);
}
}
}

Enumeration getOutputStreams() {
return outputStreams.elements();
}

public void sendToAll(String message) {
for (Enumeration e = getOutputStreams();e.hasMoreElements();)
{
PrintWriter p = (PrintWriter)e.nextElement();
try {
p.println(message);
}
catch (Exception ex) {
System.out.println("Error in sendToAll:" + ex);
}
}
}
}

class ConnectionThread extends Thread {
private PrintWriter out;
private Socket socket;

public ConnectionThread(Socket s, PrintWriter o) {
this.socket = s;
this.out = o;
}

public void run() {
try {
out.println("hello from server");
socket.close();
}
catch (Exception e) {
System.out.println("Erroe closing:" + e);
}
}
}
________________________

client:
_______________________
/*
* ChatApplet.java
*
* Created on 2001. svibanj 09, 13:31
*/


/**
*
* @author Administrator
* @version
*/
import java.net.*;
import java.util.*;
import java.io.*;

public class ChatApplet extends java.applet.Applet {

/** Initializes the applet ChatApplet */
public void init () {
initComponents ();
ChatClient client = new ChatClient("localhost",8001);
try {
BufferedReader reader = new BufferedReader(new
InputStreamReader(client.in));
PrintWriter writer = new PrintWriter(new
OutputStreamWriter(client.out));
textField1.setText(reader.readLine());
}
catch (Exception e) {
System.out.println("Error while creating reader and
writer:" + e);
}
}

/** This method is called from within the init() method to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents() {
textField1 = new java.awt.TextField();
button1 = new java.awt.Button();
button2 = new java.awt.Button();
textArea1 = new java.awt.TextArea();
setLayout(new java.awt.BorderLayout());

textField1.setBackground(java.awt.Color.white);
textField1.setName("textfield1");
textField1.setFont(new java.awt.Font ("Dialog", 0, 11));
textField1.setForeground(java.awt.Color.black);
textField1.setText("textField1");

add(textField1, java.awt.BorderLayout.SOUTH);


button1.setFont(new java.awt.Font ("Dialog", 0, 11));
button1.setLabel("Send");
button1.setName("button1");
button1.setBackground(new java.awt.Color (212, 208, 200));
button1.setForeground(java.awt.Color.black);

add(button1, java.awt.BorderLayout.EAST);


button2.setFont(new java.awt.Font ("Dialog", 0, 11));
button2.setLabel("Quit");
button2.setName("button2");
button2.setBackground(new java.awt.Color (212, 208, 200));
button2.setForeground(java.awt.Color.black);

add(button2, java.awt.BorderLayout.WEST);


textArea1.setBackground(java.awt.Color.white);
textArea1.setName("text1");
textArea1.setFont(new java.awt.Font ("Dialog", 0, 11));
textArea1.setForeground(java.awt.Color.black);

add(textArea1, java.awt.BorderLayout.CENTER);

}


// Variables declaration - do not modify
private java.awt.TextField textField1;
private java.awt.Button button1;
private java.awt.Button button2;
private java.awt.TextArea textArea1;
// End of variables declaration

}

class ChatClient {
public InputStream in;
public OutputStream out;

private Socket c;

public ChatClient(String host, int port) {
try {
c = new Socket(host,port);
in = c.getInputStream();
out = c.getOutputStream();
}
catch (IOException ioe) {
System.out.println("Error creating client:" + ioe);
}
}
}

0 new messages