Fixed socket write bugs