Why are you closing your listening socket, then recreating it? Seems like asking for trouble to me. Are you sure that its getting recreated properly? I tried similar code to yours, and on the recreation of the listening socket, it errrored out as the Address already being in use. Is it really necessary to recreate that socket? Also, are you intending on handling multiple clients? If so you'd better change this up a bit. You can see an example of a polling loop that works