The way you post your question is as though you want people to take an educated guess of what the issue is and expect them to solve it. When asking a question, especially for socket related matters, it's best to be as detailed as feasible, not just to post your code in a piecemeal fashion. Unless, of course, the website your socket connects to is a private one that you wish not for it to be disclosed.
Anyway, at the start of the socketmark, you may need to
the apply wims's else bit with it. This will avoid the headers being written.