Added error function and reading by character from socket.