Home > OS >  python/ websocket implementation of sending messages to the client that keeps the socket open
python/ websocket implementation of sending messages to the client that keeps the socket open

Time:12-03

Help me figure out how to implement it correctly. The bottom line: The client is charging stations that connect, open a socket and send messages to the server and receive responses. Server - listens to the port, sees the connected station, receives messages and sends responses to them. Question: When the client connects and sends headers, I can send a message to the client. But I need to periodically send messages to the client that keeps the socket open, I don't understand how to implement this. Can someone tell me?

sample sending code:

charge_point_id = path.strip('/')
    cp = client_main(charge_point_id, websocket)
    logging.info(charge_point_id)
    print(charge_point_id)
    print(path)
    await websocket.send(json.dumps([2,"222", "GetLocalListVersion", {}]))
    await cp.start()

example of receiving a message from a client:

class client_main(cp):

        errors = False
            
        if not errors:
            
                        
            @on('BootNotification')
            def on_boot_notitication(self,    charge_point_vendor, charge_point_model,charge_point_serial_number,firmware_version, 
                                     meter_type, **kwargs):
               return call_result.BootNotificationPayload(
                    status="Accepted",
                    current_time=date_str.replace(' 00:00','Z'),
                    interval=60
                )

CodePudding user response:

This is impossible to do. You can send a message only when the client is connected.

CodePudding user response:

in this case, the charging station according to the ocpp protocol opens the connection and keeps it open, it should be possible to somehow write to him

  • Related