Reputation: 479
I have a simple chat app written in javascript(client and node server) with socket.io. Users are permanently connected to server. I need to test how my application behaves when connection with node-socket.io-server being dropped. I need to block socket.io connection for a few seconds and then allow my app to connect again. I need to do it using the browser, without stopping the server.
I know that chrome developer tools has a future of simulating offline mode but this future does not drops/blocks socket.io connections.
So, how can i drop socket.io connection for a few seconds using chrome browser?
Upvotes: 4
Views: 1144
Reputation: 4669
It's possible to simulate disconnection using firewall rules on either the backend or the client side.
On the client side you need to drop all outbound packets to the server, for a few seconds
Example using iptables
(will work on linux clients):
SERVER_IP="1.1.1.1"
# Append rule
iptables -A OUTPUT -d $SERVER_IP -j DROP
sleep 5
# Delete rule
iptables -D OUTPUT -d $SERVER_IP -j DROP
On the server side you need to drop all inbound packets from_the specific client, for a few seconds
Example using iptables
(will work on linux clients):
CLIENT_PUBLIC_IP="2.2.2.2"
# Append rule
iptables -A INPUT -s $CLIENT_PUBLIC_IP -j DROP
sleep 5
# Delete rule
iptables -D INPUT -s $CLIENT_PUBLIC_IP -j DROP
Upvotes: 1