This is a homework assignment just to clarify.
The problem is, I have a client and server connection however I am sending a class I made namely "Course", through to the server over a socket connection (TCP). This is where I am encountering a problem with an IOexception.
public void handleMessageFromClientUI(Object message)
{
try
{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("message.ser"));
sendToServer(out);
}
catch(IOException e)
{
clientUI.display
("Could not send message" + e.getCause());
quit();
}
}
I'm sending a course object that I have serialized, but I keep getting the cause of the exception as being null. For the purpose of simplicity and because I have a lot of other classes and code I've only put this snippet here, however I can add more if needed. Any help to point me in the right direction would be greatly appreciated!
I have added sendToServer() on request
final public void sendToServer(Object msg) throws IOException {
if (clientSocket == null || output == null){
throw new SocketException("socket does not exist");}
output.writeObject(msg);
}
Further testing shows that I may have the variable output as null which is why I get the exception.
output = new ObjectOutputStream(clientSocket.getOutputStream());
That's the initializing statement for output, very confused but I think I just moved a step forward.
Thanks.