Problems in Socket Applet
I wonder if there was a way to be able to communicate with an applet client sockets? As soon as I start my applet I start my server, I have always a "access denied" when it works perfectly on my JVM locally. What should I do to solve this problem? (I have for now tested only with html and not with jsp). I am using the following as my socket class :
Code:
import java.io. *;
import java.net.*;
public class Server (private final static int port = 5000;
public static void main (String [] args)
throws IOException (ServerSocket ss; ss = new ServerSocket (port);
Socket s; Communication sal; sal = new Communication (); Connection c; System. out.
System.out.println ("server ready, awaiting shipment at port" + port) while (true)
(s = ss. accept () c = new Connection (s, sal) sal. Add (c); c. start ();)) public int getPort () (return port;))
Please help me in solving my issue.
Re: Problems in Socket Applet
It is very tough to decide what problem exactly that you are facing.!! It would be better if you provide the coding that are using in another applet. Because without that many (including I:wink:) members cannot give you an appropriate solutions. So my kind request for you is to provide the coding first and then we will definitely try to resolve your problem.
Re: Problems in Socket Applet
Extremely sorry for not providing enough information in my post. My client applet (which itself launches other windows) :
Code:
import java.io. *;
Import javax.swing.JApplet;
public class extends JApplet (ClientChat
public void init () (
this. setSize (200, 200);
Window f;
try (
f = new Window ("Cat");
while (true) (
/ / Pass information to servers
BufferedReader in;
in = f. getin ();
f. receive ();
)
) Catch (IOException e) (
// TODO Auto-generated catch block
e. printStackTrace ();
)
)
)
Re: Problems in Socket Applet
An applet can not create server socket (that's if you planned to put your first code in an applet, but I doubt AC would not make sense). Log (Client therefore) via socket to a server other than that which comes from the page in which it finds itself (that is to avoid pages that hackers would run applets intended to serve as a relay for spam, for example :wink: ). So in your case, simply that your server runs on the same server where have your web page. If it does not work, we post the exception + code associated with the line the exception (we see nothing of what your client in your code).
Re: Problems in Socket Applet
I throw over my html file:
HTML Code:
<! DOCTYPE html PUBLIC "- // W3C // DTD HTML 4.01 Transitional //" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body style= "margin:auto;">
<div style= "width:320px;margin:auto;margin-top:100px;border:5px solid black">
<applet codebase= "bin/" code= "ServerChat.class" height= "80" width= "300" hspace= "10" vspace= "10">
<param name= "ipServer" value= "localhost">
<param name= "portServer" value= "5000">
</ Applet>
</ Div>
</ Body>
</ Html>
Re: Problems in Socket Applet
Do you sign your code? Indeed, using sockets is to use a hardware component, the network adapter. Outside, access to a hardware device by an applet is restricted by security java browser plugin. This default allows no access. Clearly, an unsigned applet can only act on the elements of the page that contains the point. To go further it is imperative to create a signing certificate and use it to sign code. Thus, when the user tries to execute a code applet that will seek to use its card network to make a socket connection, the signing certificate to be submitted so that it can identify the author of the code and decide to trust or not confirm or deny the execution of code. And obviously the only condition of acceptance that the applet can then create a socket, whether client or server.
Re: Problems in Socket Applet
Indeed, it is troubling. In this case, it is not impossible to imagine a security restriction to your own browser. What do you use as your browser? Anyway, unless you only use your applet, it will have to distribute one day, and there it will be loaded via an HTTP URL, so you do not cut. So much to start with that, and if it does not change your behavior, examine the management of your security, I know from experience that IE in its latest version by default blocks this kind of thing.
Re: Problems in Socket Applet
Regarding the validation of the certificate, it concerns the confidence given to the developer, not that it allows itself. A developer honest when signing the code of its applet knowing that it has access only besion socket will ensure that its code that accesses the socket. At least I think he made the approach by the CAs. It should not imagine that because recognize a signature that will last all the code. Now, such a signature is not free. Then if we know the developer personally and recognize that his signature and that he trusted, there is no need to bother with all this. But if I understand it, when you write an applet itself, assume it is actually needed to be signed, how you doing? You all the rights granted by submitting a certificate created by yourself?