Combining a server and client probably isn't appropriate. They should run on different threads, which should also be separated from their work and GUI threads, respectively. All of them can be in the same .exe, though.
Although it may be more than what you're looking for, here's an example of a UDP thread. It only receives messages because the applications send messages without queueing them for output: UdpIoThread.cpp