'Websocket server stops getting new messages from client if it doesn't send a response followed by the client explicitly receiving the response

First of all, I don't believe this is a connection issue as my connection seems to stay alive during the duration of this problem:

I have a WebSocket server that is supposed to serve on a port, and let a particular client send information. This will be relayed to other clients later, but for now, let's simply print().

 async def networkresponse(self, websocket):
    async for message in websocket:
        print(message)
        # await websocket.send(message) #later make this will be relayed instead

This client does not care about anything the server has to say, he is only supposed to connect, send things, and be done.

    import asyncio
    import websockets    
            
    async def send_stuff(combDf):
                # connect socket
                async with websockets.connect("ws://localhost:8765") as websocket:
                    for i in range(100):  
                        time.sleep(2)
                        await websocket.send("sillyness")
                        #print("client received from server", await websocket.recv())
                        print("sent: " + "silliness")
    asyncio.run(send_stuff(df))

My problem is that the server doesn't ever gets anything unless i UNCOMMENT out the line in the server code to send a response to the client AND UNCOMMENT out the code on the client side for receiving the message. I do not understand why this is, and it is not the behavior I want.

This is all running on localhost, and if I look at Wireshark, I see no ws messages unless I uncomments the lines mentioned above. It is almost like nothing is sent on the wire unless there is a successful send and receive each time- even though I don't want the server to send anything to this client,only listen to his messages.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source