first version of main method that connects sockets
refactoring of main method