Move code for connecting to server to a new class

Signed-off-by: Igor Popov <igor.popov89@gmail.com>