You would use something like this:
If you want to keep a socket open, or read back from the socket, it gets a whole lot more complicated.