createSocket rewritten