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
If anyone could even hasard a guess at the issue I would appreceate it,
also here is output from the java console if its anyhelp.
load: ClientConference.class can't be instantiated.
java.lang.InstantiationException: ClientConference
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Thanks in advance I really appreceate any help
Niall
public ClientConference()
{
// do nothing here
}
> at sun.applet.AppletPanel.createApplet(Unknown Source)
> at sun.plugin.AppletViewer.createApplet(Unknown Source)
> at sun.applet.AppletPanel.runLoader(Unknown Source)
> at sun.applet.AppletPanel.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
>
>
> Thanks in advance I really appreceate any help
> Niall
>
Furthermore you should override the applet's init() and destroy()
methods, and may be start() and stop(), too.
See http://java.sun.com/j2se/1.4.2/docs/api/java/applet/Applet.html for
information when your browser calls those 4 methods.
Then you can split up the code you had in your original constructor, and
move its parts into those methods.
--
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')