correct syntax for tcp socket connection, close sockets appropriately