What IPC method should I use between Firefox extension and C# code running on the same machine?

后端 未结 4 1777
野性不改
野性不改 2021-01-03 05:49

I have a question about how to structure communication between a (new) Firefox extension and existing C# code.

The firefox extension will use configuration data and

相关标签:
4条回答
  • 2021-01-03 06:24

    I would personally used named pipes to do the communication instead of sockets. They're very low overhead, and very reliable on Windows.

    This is very easy to use from C++ and from C#.

    0 讨论(0)
  • 2021-01-03 06:24

    Well if you're going to use JavaScript I don't see another way to use named pipes or other system dependant communication other than writing proxy component in C++ which will allow you to access OS API directly. On the other hand if you plan to use TCP/UDP for IPC it will be much easier for you, because Firefox provides socket services that you can use easily from JavaScript component.

    If blocking is your concern you can use asynchrony socket communication or threading services to avoid locking of Firefox's GUI, but be aware that many objects are accessible only from Firefox's main thread.

    0 讨论(0)
  • 2021-01-03 06:29

    The option I selected was #2: use a sqlite db. Main advantages being:

    • possible to implement in javascript
    • using a sqlite db useful for other reasons
    • asynchronous communication improves performance: C# code is able to cache all information the firefox extension requires rather than having to prepare it on-demand. FF extension is able to save all data back to the sqlite db rather than needing it handled immediately by C# code.
    • separate layer provides a nice testing-point, e.g. it's possible to run only the FF code and verify the expected results in sqlite, instead of needing a testing harness that operates across FF and C#.

    Clearly some of these are scenario-dependant, so I would definitely not say this is the best general-purpose option for communication between FF extn and C# service.

    UPDATE: We used just a sqlite db initially, and then wanted some synchronous communication so later exposed an http web service from the C# windows service that is called by the FF extension. This web service is now consumed by both the FF extension and other browser extensions. It's nice that it's a web service as it makes it easy to consume by different apps in different languages.

    0 讨论(0)
  • 2021-01-03 06:32
    1. Use the first if you need any sort of RPC. Otherwise, you'll find yourself writing an RPC language, validations, construction/deconstruction, etc., just a little overboard for something on a local machine.

    2. Best option if you have a very passive plugin. The third component entirely decouples the two processes, which is great for a lot of things, including as mentioned above, async, testing, ease of implementation, etc.. Probably a silly idea if you want to do a lot of message passing.

    3. Probably the best option overall for most things. TCP/IP is nice from the standpoint of sending stuff across the internet, but you don't really want two different IP addresses or to mess around with setting up webservers and possible port conflicts. Pipes make more sense, or some other similar serial communication model. It decouples well, it can be entirely async (TCP/IP is async, normal HTTP is not, pipes are too), its very easy to test (assuming you don't have to write any of the protocol of course), and it couldn't care less about code base. Which means tomorrow, if your C# backend turns into say, a Ruby one, or a Python one, the entire thing still 'just works'. Its better than sqlite as well, since you don't have to worry about packaging an entire library and database with your plugin.

    The only downsides to the third option, is (one) that things will be async but should be responsive and active, whereas sqlite allows things to not only be mostly passive, but it isn't phased by you shutting your computer down for a week. And (two) its not amazing for RPC either, if you want to do that again you end up inventing your own protocol or dealing with something like SOAP and WSDL.

    0 讨论(0)
提交回复
热议问题