所以我一直致力于一个项目,其中运行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) 我正在尝试解决StartUpASP.Net WebApi 2项目的类中的依赖项.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问题,是否有一个简单的解决方案?有人可能更清楚我是如何实现这一点的吗?提前致谢!