1) Read the section on Sockets in the help file.
2) Search the forum for the term socket
3) Review the scripts that are returned in that search.
4) Make and test your best attempt.
5) Ask here, with a posting of your code, for assistance in getting it working and/or recommended changes to make it faster/better.