ok, so i changed the client and created a class that has the main method where i create a client but nothing happened. I would run the client and i never got any exceptions or messages it would just quit. I changed the sendData method to public and passed it a string but when i do that and run the client i get a nullPointerException. It occurs in the sendData method at the output.writeObject(data) line and in main at the line where i tell it to send the data. I'll post the client and server again.
Server
import java.net.*;
import java.io.*;
//import java.net.*;
public class Server
{
private static Socket connection;
private static ObjectOutputStream output;
private static ObjectInputStream input;
public static void main(String[] args) throws java.io.IOException
{
ServerSocket s = new ServerSocket(1234);
while(true)
{
connection = s.accept();
System.out.println("client connected");
streams();
//send("Send this to client");
//System.out.println("Listenning...");
//(new ServerThread(s.accept())).start();
//System.out.println("Spawned Thread.");
} // end while
} // end main
// establish the streams
private static void streams() throws IOException
{
output=new ObjectOutputStream(connection.getOutputStream());
output.flush();
input=new ObjectInputStream(connection.getInputStream());
} // end streams
private static void send(String or_variable)
{
try
{
output.writeObject("String" + or_variable);
output.flush();
} // end try
catch(IOException ioException)
{
}
} // end send
} // end Server
client
import java.io.*;
import java.net.*;
import java.util.*;
public class Client
{
private Socket client;
private ObjectOutputStream output;
private ObjectInputStream input;
//Client constructor
private void client()
{
try
{
connect();
streams();
processConnection();
} // end try
catch (EOFException eofException)
{
System.err.println("Client terminated connection");
} // end catch
catch (IOException ioException)
{
ioException.printStackTrace();
} // end catch
finally
{
closeConnection();
} // end finally
} // end client
private void connect() throws IOException
{
System.out.print("Attempting Connection\n");
client = new Socket(InetAddress.getByName("192.168.1.102"), 1234);
System.out.print("Connected to: " + client.getInetAddress().getHostName());
} // end connect
private void streams() throws IOException
{
output=new ObjectOutputStream(client.getOutputStream());
output.flush();
input=new ObjectInputStream(client.getInputStream());
System.out.print("\nStreams Estabolished\n");
} // end streams
private void processConnection() throws IOException
{
String test = "";
do
{
try
{
test = (String)input.readObject();
System.out.print("\n" + test);
} // end try
catch(ClassNotFoundException classNotFoundException)
{
System.out.print("\nUnknown object recieved");
} // end catch
}while(!test.equals("Server Connection Lost")); // end do while
} // end processConnection
private void closeConnection()
{
try
{
output.close();
input.close();
client.close();
} // end try
catch(IOException ioException)
{
ioException.printStackTrace();
} // end catch
} //closeConnection
public void sendData(String data)
{
try
{
output.writeObject(data);
output.flush();
} // end try
catch(IOException ioException)
{
System.out.print("\nError writing object");
} // end catch
} // end sendData
} // end client
newMain, this is the main method for the Client
public class newMain
{
public static void main(String[] args)
{
Client c = new Client();
c.sendData("here you go");
} // end main
} // end newMain