This code is a little redundant as calling available() often will subsequently close any sockets.