You can use some timeout, but as always, how long should the timeout be to ensure that you will always pass the test, but still not slow down your tests too much?
I would just check the code parsing. This is probably the place where you will have most errors, and where you most need unit tests. And it's just a check!
Then for the code that listens on the socket ... well, you might have errors here ... but if it just sends data to a function / class, I'm not sure if you really need to test it. And if you want to be very thorough, how are you going to unit test, that your class behaves well if the connection is lost between the client and server, for example?
source share