[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: java applet problem
> > > Is the applet being run off of a server (ie. a http URL)? If the
> applet
> > > were running from the user's local disk through a file:// URL then the
> > > security restriction of being able to connect only back to the server
> that
> > > sent the .class files does not apply.
> > As long as we're using "appletviewer", it doesn't matter...
> > But this doesn't seem to hold true when using a browser(i used
> > netscape).
>
> I am almost certainly sure that when you open a page using the file:// URL
> (ie. a page local to your hard disk) and when this page contains an applet
> which is also local to your hard disk the "connect back only to server
> sending this applet" does not apply.
I'm afraid this is not true. Browser security exceptions are thrown in
both cases... the URL being file:// or being http:// doesnt make a
difference.
------------------------8<---------cut here--------8<-----------------
import java.awt.*;
import java.net.*;
import java.io.*;
public class Socklet extends java.applet.Applet {
String serverName;
int portNumber;
public void init() {
serverName=getParameter("serverName");
portNumber=Integer.parseInt(getParameter("portNumber"));
setBackground(Color.white);
}
public void paint(Graphics g) {
for(;;) {
try {
Socket socket=new Socket(serverName,portNumber);
PrintWriter writer=new PrintWriter(new
OutputStreamWriter(
socket.getOutputStream()),true);
BufferedReader reader=new BufferedReader(new
InputStreamReader(socket.getInputStream()));
g.drawString("SERVER SAYS:" + reader.readLine(), 10,10);
Thread.sleep(6000);
} catch (Exception e) {g.drawString("Error!" + e
,10,10);}
}
}
}
------------------------>8---------cut here-------->8----------
HTML file to test: <Change the ServerName parameter to test>
<html>
<head>
<title>
Test Socklet
</title>
</head>
<body bgcolor="white">
<center>
<applet code="Socklet.class" height=100 width=600>
<param name="ServerName" value="157.227.12.225">
<param name="portNumber" value="25">
</applet>
</center>
</body>
</html>
--
There is a natural hootchy-kootchy to a goldfish.
-- Walt Disney
===========================================================
R o h i t R o m e h a r s h a n S i n g h
WORK:rohitsingh@xxxxxxxxxxxxxxx PLAY:rohit@xxxxxxxx