Found out ws are not really a streaming protocol. Can't rely on messages sent one at a time. Solution: send a 0 to indicate shape end.