make code more flexible, fixing some bugs in client app and adding idle timeout to socket