implement the onopen, onmessage and onerror method