How to compress a string?

So I want to “compress” a string so it takes up less recv when send via a remote. But I don’t really know how. I know how to buffer numbers but not strings.

Is there a way to do so?