Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
SecurityException in Applet mit DatagramSocket
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Andreas Krug  
View profile  
 More options Aug 4 1999, 3:00 am
Newsgroups: de.comp.lang.java
From: "Andreas Krug" <a...@internet-shop.net>
Date: 1999/08/04
Subject: SecurityException in Applet mit DatagramSocket
Hallo,
Kann es sein das man in Applets keine DatagramSocket verwenden kann ?
Obwohl Applet und Server auf der gleichen Maschine laufen erhalte ich
folgende Exception:

com.ms.security.SecurityExceptionEx[udp/udpapplet.button1_actionPerformed]:
cannot access 0
 at com/ms/security/permissions/NetIOPermission.check (NetIOPermission.java)
 at com/ms/security/PolicyEngine.deepCheck (PolicyEngine.java)
 at com/ms/security/PolicyEngine.checkPermission (PolicyEngine.java)
 at com/ms/security/StandardSecurityManager.chk
(StandardSecurityManager.java)
 at com/ms/security/StandardSecurityManager.checkListen
(StandardSecurityManager.java)
 at java/net/DatagramSocket.create (DatagramSocket.java)
 at java/net/DatagramSocket.<init> (DatagramSocket.java)
 at udp/udpapplet.button1_actionPerformed (udpapplet.java:106)
 at udp/udpapplet$1.actionPerformed (udpapplet.java:67)
 at java/awt/Button.processActionEvent (Button.java)
 at java/awt/Button.processEvent (Button.java)
 at java/awt/Component.dispatchEventImpl (Component.java)
 at java/awt/Component.dispatchEvent (Component.java)
 at java/awt/EventDispatchThread.run (EventDispatchThread.java)

das Applet:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import com.borland.jbcl.layout.*;
import com.borland.jbcl.control.*;
import java.io.*;
import java.net.*;

public class udpapplet extends Applet  implements Runnable {

  // zum Beenden
    boolean aus = false;

    int inPort = 20532;
    int outPort = 20531;

    Thread th;
    InetAddress addr = null;
    String name = "";

  boolean isStandalone = false;
  BorderLayout borderLayout1 = new BorderLayout();
  Panel panel1 = new Panel();
  TextField textField = new TextField();
  Button button1 = new Button();
  TextArea textArea = new TextArea();

  String server = "lux.internet-shop.net";

  public void init() {
   try  {
      name = "Client"+Math.round(Math.random()*1000);
      // Serverdaten initialisieren
      addr = InetAddress.getByName( server );
      // Namen senden
      byte inhalt[] = name.getBytes();
      DatagramPacket paket = new DatagramPacket( inhalt,
        inhalt.length, addr, outPort );
      DatagramSocket outsocket = new DatagramSocket();
      outsocket.send( paket );
      outsocket.close();

      jbInit();

// Ende der Eingabe durch den Benutzer, Server-Horcher beenden
      aus = false;
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

private void jbInit() throws Exception {
    this.setLayout(borderLayout1);
    textField.setColumns(40);
    textField.setText("textField1");
    button1.setLabel("send");
    button1.addActionListener(new java.awt.event.ActionListener() {

      public void actionPerformed(ActionEvent e) {
        button1_actionPerformed(e);
      }
    });
    textArea.setText("textArea1");
    this.add(panel1, BorderLayout.NORTH);
    panel1.add(textField, null);
    panel1.add(button1, null);
    this.add(textArea, BorderLayout.CENTER);
  }

public void start() {
    if (th == null)
      th = new Thread(this);
    th.start();
  }

  public void stop() {
    th = null;
  }

  void button1_actionPerformed(ActionEvent e) {
     try {
      // Kommandos lesen und an Server schicken
      String s = textField.getText();
      byte inhalt[] = s.getBytes();
      DatagramPacket paket = new DatagramPacket( inhalt,
        inhalt.length, addr, outPort );
      DatagramSocket outsocket = new DatagramSocket();
      outsocket.send( paket );
      outsocket.close();
    } catch ( Exception ex ) { ex.printStackTrace(); }
  }

  public void run() {
      byte[] puffer = new byte[1024*2];
      try {
        while ( ! aus ) {
          DatagramSocket inpsocket = new DatagramSocket( inPort );
          DatagramPacket paket =
            new DatagramPacket( puffer, puffer.length );
          inpsocket.receive( paket );
          System.out.println( name + " Habe " + paket.getLength() + " Bytes
empfangen" );
          String nachricht = new String( puffer, 0, paket.getLength() );
          textArea.appendText( nachricht + "\n");
          inpsocket.close();
          th.sleep( 300 );
        }
    } catch ( Exception e ) {
      e.printStackTrace();
      aus = true;
    }
  }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ingo R. Homann  
View profile   Translate to Translated (View Original)
 More options Aug 4 1999, 3:00 am
Newsgroups: de.comp.lang.java
From: "Ingo R. Homann" <ihom...@techfak.uni-bielefeld.de>
Date: 1999/08/04
Subject: Re: SecurityException in Applet mit DatagramSocket
Andreas Krug schrieb:

> Hallo,
> Kann es sein das man in Applets keine DatagramSocket verwenden kann ?
> Obwohl Applet und Server auf der gleichen Maschine laufen erhalte ich
> folgende Exception:

>...

Hi!

Das entscheidende ist nicht, wo das Applet laeuft, sondern auf welchen
Server die Socket-Verbindung hergestellt werden soll. Das soll naemlich
der selbe sein, wie der, von dem das Applet aus geladen wurde.

Wahrscheinlich kann man die Problematik aber umgehen, schau' dir mal die
Klasse SecurityManager an, da gibt's ne Methode namens
enablePrivilege(). Die duerfte weiterhelfen. Dann wird der User vom
Browser gefragt, ob er so eine Connection erlaubt, und er kann das
bestaetigen.

Bye, Ingo!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »