Rename trim() to rtrim() and add ltrim()
Add socket close function