新增 socket 代码
from  http://www.cnblogs.com/skynet/archive/2010/12/12/1903949.html