P
Pontus
Hello!
Tried to write an applet that connects to a server with sockets. The code
below works in the appletwiever but I get a SecurityException with Internet
Explorer 5.5 when
the applet reads Socket socket=new
Socket(this.getCodeBase().getHost(),port);
I think I have tried it all and I have also searched the net for answer.
How should I do to have the applet write "javaworld" and not receive the
SecurityException "cannot access "127.0.0.1":5000" ?
(If you test the code below, execute the server first and then the client)
Thanks in advance!
/Pontus
The Client:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.applet.*;
public class AppletClient extends Applet{
public void init(){
Label label=new Label(" ");
int port=5000;
add(label);
try{
Socket socket=new Socket(this.getCodeBase().getHost(),port);//will be
SecurityException.
BufferedReader bufferedreader=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printwriter=new PrintWriter(socket.getOutputStream(),true);
printwriter.println("java");
String string=bufferedreader.readLine();
label.setText(string);// should be "javaworld", but not.
}
catch(Exception error){
label.setText(error.getMessage());//cannot access "127.0.0.1":5000
}
}
}
The server:
import java.net.*;
import java.io.*;
public class Server{
public static void main(String args[]){
int port=5000;
try{
ServerSocket serversocket=new ServerSocket(port);
Socket socket=serversocket.accept();
BufferedReader bufferedreader=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printwriter=new PrintWriter(socket.getOutputStream(),true);
String string1=bufferedreader.readLine();
String string2=string1+"world";
printwriter.println(string2);
}
catch(IOException error){}
}
}
The HTML-file:
<html>
<body>
<applet code=AppletClient.class width=300 height=300></applet>
</body>
</html>
Tried to write an applet that connects to a server with sockets. The code
below works in the appletwiever but I get a SecurityException with Internet
Explorer 5.5 when
the applet reads Socket socket=new
Socket(this.getCodeBase().getHost(),port);
I think I have tried it all and I have also searched the net for answer.
How should I do to have the applet write "javaworld" and not receive the
SecurityException "cannot access "127.0.0.1":5000" ?
(If you test the code below, execute the server first and then the client)
Thanks in advance!
/Pontus
The Client:
import java.io.*;
import java.net.*;
import java.awt.*;
import java.applet.*;
public class AppletClient extends Applet{
public void init(){
Label label=new Label(" ");
int port=5000;
add(label);
try{
Socket socket=new Socket(this.getCodeBase().getHost(),port);//will be
SecurityException.
BufferedReader bufferedreader=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printwriter=new PrintWriter(socket.getOutputStream(),true);
printwriter.println("java");
String string=bufferedreader.readLine();
label.setText(string);// should be "javaworld", but not.
}
catch(Exception error){
label.setText(error.getMessage());//cannot access "127.0.0.1":5000
}
}
}
The server:
import java.net.*;
import java.io.*;
public class Server{
public static void main(String args[]){
int port=5000;
try{
ServerSocket serversocket=new ServerSocket(port);
Socket socket=serversocket.accept();
BufferedReader bufferedreader=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printwriter=new PrintWriter(socket.getOutputStream(),true);
String string1=bufferedreader.readLine();
String string2=string1+"world";
printwriter.println(string2);
}
catch(IOException error){}
}
}
The HTML-file:
<html>
<body>
<applet code=AppletClient.class width=300 height=300></applet>
</body>
</html>