First of all, your sockopen command is opening "dictionarysock" (from my script). You didn't change it to clansock.
Second, you have a sockclose dictionarysock in there too. That can also be removed.
Third, your code here looks like some lines are split onto multiple lines. I'm not sure if that is how it is in your script, or just how it came out here. I'd check it out to be sure.