Giter VIP home page Giter VIP logo

Comments (7)

mikuso avatar mikuso commented on July 22, 2024 1

Ah, I see.

The main reason why this library doesn't index the clients for you is because there are so many different ways in which you might want to do it. You could easily find yourself in a situation where you have multiple clients connecting with the same (duplicate) identities, but differing protocols, paths, "virtual" hosts, etc...

Anyway, I'm glad this solution works for your case. Thanks.

from ocpp-rpc.

mikuso avatar mikuso commented on July 22, 2024

Hi @ease

Is the express server instance and RPCServer instance part of the same application? Or is the express server running in one application and the RPCServer running in the other?

You can use this module for implementing RPC between different applications, although I suspect this may not be what you need.

from ocpp-rpc.

ease avatar ease commented on July 22, 2024

It's the latter -> express server running on port 3000 and the RPCServer running on 80.

Since client identity and RPCServer instance are important to me and I'd like to comply with the rules you've put in the lib, what would you recommend for express server to RPCServer communication? If it wasn't this library and doing it via WebSockets (e.g. ws) we'd just emit event from express and listen to it on the WebSocket server. Here I'm trying to do the same in a correct way using your library and hoping to get some guidance on how to do it properly and what could be the right method I should use? How can I access the underlying socket and send events from the backend to RPCServer? I thought it's sendRaw as mentioned above.

Thanks for the quick response.

from ocpp-rpc.

mikuso avatar mikuso commented on July 22, 2024

If you wanted to send messages to an RPCServer, then you'd be best to use an RPCClient. There's no reason to use sendRaw unless you're doing some low-level debugging of the protocol.

You can create an RPCClient instance alongside your express app and have it connect to your existing RPCServer using a custom protocol. This would allow you to re-use the RPCServer to serve both your OCPP chargepoints and your custom RPC protocol at the same time.

from ocpp-rpc.

ease avatar ease commented on July 22, 2024

Yeah that makes sense and I've managed to pass the data using a custom protocol, but the issue I have with that is that I have a single reference to the client in

server.on('client', (client) => {
    // Here, I'll have a reference to the RPCClient which is my express app, but I'd also like to have 
    // the ability to talk to charger that'd also be connected to this server

    // I'd like to catch the event from the custom protocol (from backend) here and pass it to the 
    // charger to perform `.call` on the charger, not on the RPCClient which is my express backend.
})

How to achieve getting both express's client reference and real charger's client reference?

Perhaps I'd need to store each of the clients in my own way as soon as I notice a new client? I was wondering if I can do that using your library since you're already filling the array/Set of _.clients with the each new incoming client, and also have implemented the methods for adding and deleting a client.

from ocpp-rpc.

mikuso avatar mikuso commented on July 22, 2024

A common way to reference different clients is by their differing identities - but you'd need to create this index yourself as the library doesn't include this as a feature.

Here's an example of how I've done this before.

You could then reference your different clients like so:

clients.get('ExpressServer').call(/* something */);
clients.get('Charger').call(/* something */);

from ocpp-rpc.

ease avatar ease commented on July 22, 2024

Thanks, I had that in mind and I'm around the same idea of using identities. I've noticed you're storing each new client under the private property (_clients) so I was thinking that I've missed something in your docs about that Map being exposed somewhere and just wanted to check.

Thanks for the suggestions, I think you can close this now.

from ocpp-rpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.