While trying to send a WebSocket transaction, I hit the following error
I received this error when working on an application that involved a WebSocket connection. The Websocket handshake between the client and server was successful. After that I was able to send data to server using ws.send(“request_data_1”). I had no trouble receiving the data using ws.recv(). But when I sent the next frame of data using ws.send(“request_data_2”), I got the Connection is already closed and socket is already closed error message. I couldn’t figure out why exactly the connection was getting closed.
After some research, I figured out that the server was expecting data in JSON format. I transformed the data being sent to json format and things started working smoothly.
When looking up this error online, I noticed Google was not very helpful. So I thought I would write this short post to help anyone else who stumbled across this error. Hope this helped!
If you liked this article, learn more about Qxf2’s testing services for startups.