fixed server code to handle arbitrary length messages