use write() instead of printing to stream, which not working (and don't know why); change the assumption that PONG must appeared at the right beginning of the line.