Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
768 views
in Technique[技术] by (71.8m points)

socket.io - JS SocketIO client with polling transport auto reconnection with updated data

I'm using only polling transport! I need to get new value at server side each time the client has been reconnected (NOT PAGE REFRESH), but the value always the same.
Socket IO JavaScript client options are:

{
    transports:['polling'],
    'reconnection': true,
    'reconnectionDelay': 500,
    'reconnectionDelayMax' : 1000,
    'reconnectionAttempts': 4,
    query: {
        anyVar:Math.random(),
    },
    path: SOCKET_SERVER_PATH + "/socket.io"
}

Server

io.on('connection', (socket: any) => {
    const anyVar:string = socket.handshake.query.anyVar;
    log("::: socket client "+socket.id+" connected. anyVar="+anyVar);
})

Server trace:

Client connected for the first time
::: socket client AZLJ5iBcaHe7fTpKAAAa connected. anyVar=0.4567

Client reconnected (NOT PAGE REFRESH)
::: socket client dWM1SbVqmh3-WEyqAABO connected. anyVar=0.4567 (hasn't changed)

Client reconnected (NOT PAGE REFRESH)
::: socket client 8qClD4t4cnd1TK55AABM connected. anyVar=0.4567 (hasn't changed)

Is it possible to send updated anyVar to server after client reconnected?

question from:https://stackoverflow.com/questions/66063276/js-socketio-client-with-polling-transport-auto-reconnection-with-updated-data

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...