新手请教websocket

我想用cocos2dx的websocket与服务器通信,服务器写好了,客户端能连上服务器,但是socket:getReadyState总是不等于cc.WEBSOCKET_STATE_OPEN,这是为什么呢?

    sendSocket = cc.WebSocket:create("ws://localhost:50000")

    local function wsSendTextOpen(strData)
        print("Send Text WS was opened.")
    end

    local function wsSendTextMessage(strData)
        local strInfo= "response text msg: "..strData    
        print(strInfo)
    end

    local function wsSendTextClose(strData)
        print("_wsiSendText websocket instance closed.")
        sendSocket = nil
    end

    local function wsSendTextError(strData)
        print("sendText Error was fired")
    end

    if nil ~= sendSocket then
        sendSocket:registerScriptHandler(wsSendTextOpen,cc.WEBSOCKET_OPEN)
        sendSocket:registerScriptHandler(wsSendTextMessage,cc.WEBSOCKET_MESSAGE)
        sendSocket:registerScriptHandler(wsSendTextClose,cc.WEBSOCKET_CLOSE)
        sendSocket:registerScriptHandler(wsSendTextError,cc.WEBSOCKET_ERROR)
    end

    print("------"..sendSocket:getReadyState())

```