N
niallmulhare
Hey, Im Attempting to create an applet that will open a connection to my
application server, the application server WILL be on the same machine
that the applet will be loaded from, i.e. the app server is on the same
machine as the web server. here is my code (sorry for the bad standards)
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
application server, the application server WILL be on the same machine
that the applet will be loaded from, i.e. the app server is on the same
machine as the web server. here is my code (sorry for the bad standards)
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