Hi all,
Ok, so I know how to write a simple client/server app where the send a message from the client and the message displays on the server's textarea, and I send a message from a server and it displays on the client's textarea.
To do this I normally use ObjectOutputStream and ObjectInputStream.
For example, this is a method in the client class used to send messages to the server:
private void sendData( String message )
{
try // send object to server
{
output.writeObject( "CLIENT>>> " + message );
output.flush(); // flush data to output
displayMessage( "\nCLIENT>>> " + message );
}
catch ( IOException ioException )
{
displayArea.append( "\nError writing object" );
}
}
However, I want to go further than that. I want to be able to declare variables, pick them, put them into the output stream and send them to the server, and I want the server to be able to take these variables one by one and store them into identical variables.
For example, if I had these in the client class:
Private String name;
Private int phoneNumber;
Private String address;
I want to be able to take them and pass them on to the server, and have the server store them in similar variables, like:
Private String ClientName;
Private int ClientPhoneNumber;
Private String ClientAddress;
How do I this?
Also, can some please explain why I have to use the ".flush" method after using an InputStream object?
Cheers