Fix bug of writeMessage checking condition. Change onMessageReceived
into abstract method.