You can check out my sockets in this script:
https://gist.github.com/memnochxx/5676bef5707a8019f0ca

In general I define an alias to create a hash table and open a socket. The socket events use this hash table (as the same name as the socket) to get the data to be passed to the server. Then I define a signal to be called when the socket is done which then reads the header and data received.

twitch.topic is probably a good starting point.