File size: 1,358 Bytes
7e59e4c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | package Client;
/*
* ClientSocketWriter.java
*/
import java.io.*;
import java.net.*;
import Common.*;
/**Writes messages to be sent to the server on the socket.
*/
public class ClientSocketWriter
{
/**The ClientNetwork whose writer this component is.*/
ClientNetwork clientNetwork;
//ObjectOutputStream output;
DataOutputStream output;
/**The constructor
* @param cn The ClientNetwork whose reader this thread is.
*/
public ClientSocketWriter(ClientNetwork cn)
{
try
{
clientNetwork = cn;
//output = new ObjectOutputStream(clientNetwork.socket.getOutputStream());
output = new DataOutputStream(clientNetwork.socket.getOutputStream());
showMessage("Got Outstream..." + output.toString());
}
catch (IOException e)
{
showMessage("An input or output exception occured while creating ObjectOutputStream");
}
}
public void writeMessageToServer(Message msg)
{
try
{
//output.writeObject(msg);
msg.writeDataObject(output);
}
catch(IOException e)
{
showMessage("An input or output exception occured while writing to socket");
}
}
/**A small function to display messages.
* @param msg The message string to show.
*/
private void showMessage(String msg)
{
System.err.println("ClientSocketWriter: " + msg);
}
}
|