Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I simulate a websocket disconnect manually? (Firefox or Chrome dev tools)

How do I simulate a websocket disconnect manually? I'm trying to test websocket reconnect logic, and I have no way of doing this other than waiting for the browser's 10 minute websocket timeout.

like image 564
thouliha Avatar asked May 17 '18 14:05

thouliha


1 Answers

With SockJS and Stomp:

socket = new SockJS(socketUrl);
stompClient = Stomp.over(socket); // global variable stompClient

Closing the underlying socket with:

socket.close();

triggered the stompClient's error handler as if the connection had been interrupted.

like image 145
Markus Pscheidt Avatar answered Sep 19 '22 08:09

Markus Pscheidt