小编Chu*_*Bun的帖子

当Android应用程序进入后台时,Websocket暂停

我的 android 应用程序启动了一个服务,该服务打开一个 websocket 以与远程服务器进行通信。该服务生成一个线程,其运行方法如下所示。

public void run() {
        try {
            super.run();

            for(int i = 1; i < 1000; i++) {
                Log.d(TAG, String.format(" *** Iteration #%d.", i));
                Thread.sleep(3000); // Dummy load.
                mWebsocket.sendTextMessage("Test");
            }
        }
        catch (Exception exc) {
            Log.d(MY_TAG, "MyThread.run - Exception: " + exc.getMessage());
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我关闭屏幕或将应用程序发送到后台时,logcat 显示循环正在运行,但远程服务器停止接收测试消息。显然,消息在某处汇集,因为一旦应用程序回到前台,服务器将收到一堆测试消息。这是 Android 上的预期行为吗?我尝试了不同的 Websocket 包(Autobahn、okhttp3、...),结果是一样的。

android websocket autobahnws okhttp3

8
推荐指数
1
解决办法
9629
查看次数

GDB:lx-symbols 未定义命令

我正在遵循以下指南:https : //www.kernel.org/doc/Documentation/gdb-kernel-debugging.txt

当我尝试使用以下命令加载模块符号时:(gdb) lx-symbols

gdb 表示该命令未定义。如何将这些帮助命令添加到 gdb?

gdb 信息:Centos 7.0 上的 gdb-7.6.1-51.el7.x86-64

linux gdb debug-symbols linux-kernel centos7

6
推荐指数
1
解决办法
4586
查看次数

Refit AliasAs 不适用于反序列化

只是想知道在 ReFit 中反序列化响应时使用 AliasAs 的正确方法是什么?如果模型中的变量名称与响应中的变量名称相同,下面的代码将正确解析响应,但如果名称不同,则返回值将为 null。

型号类别:

using Refit;
using System;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace TestRefit
{
    public class PriceModel
    {
        [AliasAs("disclaimer")]
        public string? Disclaimer123 { get; set; } 
        // "Disclaimer" or "disclaimer" work, but not "DisclaimerWhatever", "Disclaimer123", ....

        [AliasAs("charName")]
        public string? ChartName { get; set; }

    }
}
Run Code Online (Sandbox Code Playgroud)

接口类:

using Refit;
using System.Threading.Tasks;

namespace TestRefit
{
    public interface IPrice
    {
        [Get("/v1/bpi/currentprice.json")]
        Task<PriceModel> GetPrice();
    }
}
Run Code Online (Sandbox Code Playgroud)

调用:

public async void LoadPrice()
{
    var iPriceClient = RestService.For<IPrice>("https://api.coindesk.com");
    CurPrice = await …
Run Code Online (Sandbox Code Playgroud)

c# json deserialization refit

4
推荐指数
1
解决办法
1569
查看次数

具有超时的WriteAsync

我尝试使用如下所示的超时编写一个简单的异步写入,并期望该函数在给定非常大的缓冲区和小waitTime时抛出TaskCanceledException.但是,这不会发生.WriteAsync将阻塞很多秒,直到写入完成.我错过了什么?

public async void WriteWithTimeout(Stream os, byte[] buf, int waitMs)
{
    CancellationTokenSource tokenSource = new CancellationTokenSource(waitMs); // cancel after waitMs milliseconds.
    await os.WriteAsync(buf, 0, buf.Length, tokenSource.Token);

    return;
}
Run Code Online (Sandbox Code Playgroud)

从GUI线程调用:

try
{
    WriteWithTimeout(response.OutputStream, buf100M, w1ms);
}
catch(OperationCanceledException e)
{
    ConsoleWriteLine("Failed with exception: {0}", e.Message);
}        
Run Code Online (Sandbox Code Playgroud)

c# outputstream async-await cancellationtokensource

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