Use socket#close instead of socket#end