Applet Restriction's

N

niallmulhare

Hey, Im writeing my first applet (sorry) The question is im trying to write
an applet thats connect's to my application server. via.

client = new Socket( InetAddress.getByName(chatServer), 8000 );

The problem is that when I go to load the web page it the applet doesnt
load, all it gives is applet notinited , loading java applet failed, I
wrote another simple applet just to confirm my browser will display it and
it did.

Anyhelp woudld be greatly appreceated, and if I havent explained anything
well, im sorry and would be happy to explain more.

Thanking you
Niall
 
J

JavaJava

Hello Niall, can you post the entire source of your applet, and I can
have a better idea of what's going on.

Also, did you have the Java Console up when you were loading it? You
can turn it on from the browser (sometimes) or from the Control Panel
(In Windows). It will spit out log messages.

Josh
 
T

Tor Iver Wilhelmsen

niallmulhare said:
client = new Socket( InetAddress.getByName(chatServer), 8000 );

If "chatserver" is a different machine than the one the applet was
loded from, it needs to be signed in order to be allowed to connect.
 
N

niallmulhare

import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.Graphics;


public class ClientConference extends Applet {

private ObjectOutputStream output;
private ObjectInputStream input;
private String message = "";
private String chatServer;
private Socket client;

//----------------------------------------------------------------------//

public ClientConference( String host ) {
chatServer = host;
ClientConference application;
application = new ClientConference( "149.153.130.2" );
application.runClient();
}


//----------------------------------------------------------------------//
private void runClient() {

try {
connectToServer(); // Step 1: Create a Socket to make connection
getStreams(); // Step 2: Get the input and output streams
processConnection(); // Step 3: Process connection
}

// server closed connection
catch ( EOFException eofException ) {
System.err.println( "Client terminated connection" );
}

// process problems communicating with server
catch ( IOException ioException ) {
ioException.printStackTrace();
}

finally {
closeConnection(); // Step 4: Close connection
}

} // end method runClient


//----------------------------------------------------------------------//

private void connectToServer() throws IOException{
client = new Socket( InetAddress.getByName(chatServer), 8000 );
}


//----------------------------------------------------------------------//

private void getStreams() throws IOException{
output = new ObjectOutputStream( client.getOutputStream() );
output.flush();

input = new ObjectInputStream( client.getInputStream() );

output.writeObject( "Client Connected" );
output.flush();
}


//----------------------------------------------------------------------//

private void processConnection() throws IOException{

do { // process messages sent from server

// read message and display it
try {
message = ( String ) input.readObject();
}

catch ( ClassNotFoundException classNotFoundException ) { }

} while ( !message.equals( "TERMINATE" ) );

}


//----------------------------------------------------------------------//

private void closeConnection(){

try {
output.close();
input.close();
client.close();
}
catch( IOException ioException ) {
ioException.printStackTrace();
}
}


//----------------------------------------------------------------------//

private void sendData( String message )
{
// send object to server
try {
output.writeObject( "CLIENT>>> " + message );
output.flush();
}

// process problems sending object
catch ( IOException ioException ) { }
}

//----------------------------------------------------------------------//



} // end class Client

There you go, and no chatserver, in on the same machine, as I only have
one, everything is on it. Sorry if my codeing standards arent up to
scratch but I apprecate your help.
 
A

Andrew Thompson

public class ClientConference extends Applet {

I could see notihng in this code that would not work in (even) the MSVM.
Did you use '-target 1.1' when compiling?
 
A

Andrew Thompson

I could see notihng in this code that would not work in (even) the MSVM.
...
But when I compiled it and attempted to run it, I got a..

load: ClientConference.class can't be instantiated.
java.lang.InstantiationException: ClientConference
at java.lang.Class.newInstance0(Class.java:293)

( In Sun 1.5, have not even tried it in MSVM yet. )

Are you certain this is the code you are using? The *exact* code?
 
R

Roland

ClientConference.class can't be instantiated.
java.lang.InstantiationException: ClientConference
at java.lang.Class.newInstance0(Class.java:293)

( In Sun 1.5, have not even tried it in MSVM yet. )

Are you certain this is the code you are using? The *exact* code?
The constructor of ClientConference seems to be recursive, or at least
it uses the same constructor to create a new instance and assigning it
to a variable local to the constructor).

I guess, the stack overflows.

public ClientConference( String host ) {
chatServer = host;
ClientConference application;
application = new ClientConference( "149.153.130.2" );
application.runClient();
}
--
Regards,

Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
 
N

niallmulhare

Yeah that is the exact code, although for the last two days when I go to
compile it is give me a "uses or overrides a deprecated API" message, so
im wondering if it is being usng an old version stored in memory? there is
only one copy of this file, im constantly updating it. Sorry about the slow
reply pc troubles.

Niall
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top