简体   繁体   中英

Close Websockets connection

I am using Ratchet in combination with autobahnjs. I know how to close the connection on server side (by calling "close()" on the connection), but how would I be able to close the connection also on client side?

If I only close it on server side, autobahnjs will try to reconnect to the websocket even though I just kicked him out of his connection on server side.. Before kicking him out, I send a last message to the client with a flag "close" => true, afterwards I want to close the autobahnjs connection.

I thought of something like "ab.close() or ab.disconnect()", but close won't stop autobahnjs from trying to reestablish a connection and disconnect is not a known function.

have you tried voiding it?

var conn = ab.(.....)

and when you get the flag

function closeConnection(){
    conn = null;
}

this way the connection elemant is voided and is not able of reopening the connection.

I've been using Ratchet Server for my App Messenger, though I use native Javascript with it (no autobahn), I use

conn.close()

to close the client connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM