小编Kaj*_*sen的帖子

Android和Linux(RPi)之间的蓝牙连接在第一次写入操作时丢失

所以我一直致力于一个项目,其中运行Android(API级别= 14)的设备必须通过蓝牙连接到运行Linux的服务器(具体来说:Raspberry Pi).建立连接后,应用程序会将加密的XML字符串发送到RPi.RPi必须解密此字符串,解析XML并执行相应的操作.该操作的结果将发送回Android设备.

到目前为止,我已经设法在应用程序和RPi(运行最新版本的Bluez软件包)之间创建连接.RPi配备了Targus的蓝牙4.0加密狗.我坚持的地方是,当我尝试从应用程序向RPi发送字符串时.那时蓝牙插座似乎已关闭.Logcat给出了消息Connection reset by peer.

用于创建套接字的代码如下:

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);
Run Code Online (Sandbox Code Playgroud)

Logcat输出如下:

06-20 14:29:42.224: DEBUG/RPiService(24273): ---------- [ CONNECTION ESTABLISHED ] ----------
06-20 14:29:42.224: DEBUG/RPiService(24273): connected, Socket Type:Secure
06-20 14:29:42.229: DEBUG/RPiService(24273): create ConnectedThread: Secure
06-20 14:29:43.734: DEBUG/RPiService(24273): setState() 2 -> 3
06-20 14:29:43.739: DEBUG/RPiService(24273): Connection reset by peer
06-20 14:29:43.744: WARN/System.err(24273): java.io.IOException: Connection reset by peer
06-20 14:29:43.754: WARN/System.err(24273): at android.bluetooth.BluetoothSocket.writeNative(Native Method)
06-20 14:29:43.759: WARN/System.err(24273): at android.bluetooth.BluetoothSocket.write(BluetoothSocket.java:398)
06-20 …
Run Code Online (Sandbox Code Playgroud)

linux android bluetooth raspberry-pi bluez

20
推荐指数
1
解决办法
7713
查看次数

在StartUp中使用Autofac解决每用户/每请求的依赖性

我正在尝试解决StartUpASP.Net WebApi 2项目的类中的依赖项.Autofac用于配置依赖注入.方案如下:

  • 不同用户看到不同的数据.每个用户都拥有允许该用户查看某些数据的某些权限.
  • 正在使用包含多个边界的域驱动架构.不允许在域和数据访问层中进行跨境调用.这很重要,因为为了获得用户所允许数据的所有代码,我们需要进行一些跨境调用.
  • 我们希望过滤数据访问层内的数据,以便仅为每个用户检索允许的数据.这里不允许跨境通话.
  • 为了实现这一点,我想从用户可以看到的记录中注入所有代码的列表.
  • 为此,我尝试使用Autofac注册工厂,该工厂根据用户创建此列表.我们打电话给工厂StuffFactory和列表吧StuffModel.

现在的问题是所有这些都需要注册为InstancePerRequest.抛出一个InvalidOperatonException,这听起来很合理,因为请求生命周期范围无法访问StartUp

从请求实例的作用域中看不到具有匹配"AutofacWebRequest"的标记的作用域.这通常表示SingleInstance()组件(或类似场景)正在请求注册为每HTTP请求的组件.在Web集成下,始终从DependencyResolver.Current或ILifetimeScopeProvider.RequestLifetime请求依赖项,从不从容器本身请求.

允许的东西在容器中注册的代码:

private IContainer RegisterAllowedStuff(IContainer container)
{
    var builder = new ContainerBuilder();

    builder.Register(x => GetAllowedStuffForUser(container))
        .As<StuffModel>()
        .InstancePerRequest();

    builder.Update(container);
    return container;
}

private static StuffModel GetAllowedStuffForUser(IContainer container)
{
    var stuffFactory = container.Resolve<IStuffFactory>();
    return stuffFactory.CreateStuffModel(Helper.GetParsedUserName());
}
Run Code Online (Sandbox Code Playgroud)

我有点被困在如何从这里前进.对于我完全监督的Autofac问题,是否有一个简单的解决方案?有人可能更清楚我是如何实现这一点的吗?提前致谢!

c# dependency-injection autofac asp.net-web-api

3
推荐指数
1
解决办法
1240
查看次数