@Freaky Chris
I've never done it that way. A better way might be to make the socket public or the send method public. Then, in the other applications, you can call the class that has the connection and use the connection or call the send class.
ServerClass.send("something");
I could be wrong because I have not tested it to know for myself. I have only used that accessed variable from one class to other classes, but I think the logic would work.
@cwl157
Sorry, I only got to send you the sever class, but the server looks right. The client does have to be redesigned. Not implementing what you need, here's the bare bones of the client
private Socket client
private ObjectOutputStream output;
private ObjectInputStream input;
private void client(){
try{
connect();
streams();
processConnection();
}
catch (EOFException eofException){
System.err.println("Client terminated connection");
}
catch (IOException ioException){
ioException.printStackTrace();
}
finally{
closeConnection();
}
}
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());
}
private void streams() throws IOException{
output=new ObjectOutputStream(client.getOutputStream());
output.flush();
input=new ObjectInputStream(client.getInputStream());
System.out.print("\nStreams Estabolished\n");
}
private void processConnection() throws IOException{
String test = ""
do{
try{
test = (String)input.readObject();
System.out.print("\n" + test);
}
catch(ClassNotFoundException classNotFoundException){
System.out.print("\nUnknown object recieved");
}
}while(!test.equals("Server Connection Lost"));
}
private void closeConnection(){
try{
output.close();
input.close();
client.close();
}
catch(IOException ioException){
ioException.printStackTrace();
}
}
private void sendData(String data){
try{
output.writeObject(data);
output.flush();
}
catch(IOException ioException){
System.out.print("\nError writing object");
}
}
That should do it.