Writing unit tests for socket functions

I’m creating a TCP client class which will have connect/disconnect functions and a request function which takes the request data as an argument and returns the response data. My question is how I’d go about testing that my class does what it’s supposed to do.

I want to test that when I run connect() it actually connect to the url I’ve given it in the constructor.

I want to test that when I run disconnect it actually does that.

I want to test that when I run request it actually sends it to the server and returns the response that the server sends.

I’ve read http://stackoverflow.com/a/9143812/42793 and it seems like a good idea but when I try it my code just freezes when I set the server to listen.

Any tips?