Coder Social home page Coder Social logo

yehudakremer / fluttercsharprpc Goto Github PK

View Code? Open in Web Editor NEW
35.0 35.0 5.0 461 KB

Execute C# code from Dart (Flutter) application

Home Page: https://pub.dev/packages/csharp_rpc

License: MIT License

C# 16.28% Dart 83.72%
csharp ffi flutter json-rpc2 streams

fluttercsharprpc's People

Contributors

yehudakremer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fluttercsharprpc's Issues

[FEATURE REQUEST] Broadcast/Send Message from Server without Invoking any method.

Is it possible to send message from Server without having to invoke any method from client.

I have a scenario where U.are.U 4500 Fingerprint reader Emits Callbacks for different interactions with the device.

I need to send data from C# to Flutter on each interaction.

Is is possible?
If yes? Can you please provide some example code.

[FEATURE REQUEST]

๐Ÿ’ฌ Description

I have used your package csharp_rpc, and it's very useful.
but i have a problem , this package connect to one class only ,
what if i need to connect to whole dot net app , so i can access any class in it

[BUG] RPC stops accepting requests after a few seconds on .NET Framework 4.8

โ„น๏ธ Info

Version: 0.0.1

๐Ÿ’ฌ Description

Whenever I attempt to run CSharpRPC on .NET Framework 4.8, the process opens for around 2 seconds or so, then will infinitely yield upon waiting for new requests to respond. Furthermore, each time you run csharpRpc = await CsharpRpc(modulePath).start(); within the Flutter app, it creates a new process under the Flutter program, of which does not close when you stop the app from running (must be closed in Task Manager).

I've tested this in Flutter Debug, although not Release. I've also only tested this within .NET Framework 4.8 / 4.7.2, though I'd be happy to test on other versions if necessary.

๐Ÿ“œ Pubspec.yaml

name: rpc_testing
description: A new Flutter project.
publish_to: 'none'

version: 1.0.0+1

environment:
  sdk: '>=3.0.6 <4.0.0'

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2
  csharp_rpc: ^0.0.7

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^2.0.0

flutter:
  uses-material-design: true

CSharp Program

Program.cs

using FlutterCsharpRpc;
using System.Threading.Tasks;

internal class Program
{
    static async Task Main(string[] args)
    {
        await CsharpRpcServer.StartAsync(new Server());
    }
}

Server.cs

using System;

public class Server
{
    public void RunTest()
    {
        Console.Error.WriteLine($"Received new 'RunTest' request")
    }
}

csproj file

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		<OutputType>WinExe</OutputType>
		<TargetFramework>net472</TargetFramework>
	</PropertyGroup>

	<ItemGroup>
	  <PackageReference Include="FlutterCsharpRpc" Version="0.0.1" />
	</ItemGroup>
</Project>

Flutter Program

only the first doInjectLoop() stuff is important here

import 'package:flutter/material.dart';
import 'package:csharp_rpc/csharp_rpc.dart';

late CsharpRpc csharpRpc;

void doInjectLoop() async {
  print("starting loop");
  var modulePath = r"C:\Users\eric\source\repos\Project1\Project1\bin\Debug\net472\Project1.exe";
      csharpRpc = await CsharpRpc(modulePath).start();
  while (true) {
    print(await csharpRpc.invoke(method: "RunTest"));
    await Future.delayed(const Duration(seconds: 1));
  }
}

void main() async {
  doInjectLoop();
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}

Let me know if I can provide anything else!

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.