Your code works for me when I use a String for the IP. Exactly what are you passing as the IP (Socket takes several different arguments: InetAddress, String (host) String (ip))? Are you certain you were not using ServerSocket? I would expect an "Address already in use" exception if you tried to bind to the same socket a server was using. One further note, it is a good idea to put either Thread.yield or Thread.sleep calls in when writing infinite loops. That way other code can get to use the CPU once in a while.