为什么Californium在使用CoAP协议发送数据后等待65535条记录

时间:2015-04-01 10:10:03

标签: java udp coap

我使用 Californium API(https://github.com/eclipse/californium)使用CoAP协议发送数据。

以下是客户端和服务器的代码段。

服务器:

public class HelloWorldServer extends CoapServer {
    /*
     * Application entry point.
     */
    public static void main(String[] args) {
        try {
            // create server
            HelloWorldServer server = new HelloWorldServer();
            server.start();
        } catch (SocketException e) {
            System.err
                    .println("Failed to initialize server: " + e.getMessage());
        }
    }

    /*
     * Constructor for a new Hello-World server. Here, the resources of the
     * server are initialized.
     */
    public HelloWorldServer() throws SocketException {
        // provide an instance of a Hello-World resource
        add(new HelloWorldResource());
    }

    /*
     * Definition of the Hello-World Resource
     */
    class HelloWorldResource extends CoapResource {
        public HelloWorldResource() {
            // set resource identifier
            super("helloWorld");
            // set display name
            getAttributes().setTitle("Hello-World Resource");
        }

        @Override
        public void handleGET(CoapExchange exchange) {
            // respond to the request
            exchange.respond("Hello World!");
        }

        @Override
        public void handlePOST(CoapExchange exchange){
            //System.out.println("Start "+System.currentTimeMillis());
            exchange.accept();           
            //List<String> queries = exchange.getRequestOptions().getURIQueries();
        //    System.out.println("Text Received : "+ exchange.getRequestText().length());
        //    System.out.println("End "+System.currentTimeMillis());
            exchange.respond("Received");


        }
    }
}

客户代码:

try {           

            long startTime = System.currentTimeMillis();
            for (int i = 0; i < 1000000; i++) {
                CoapClient client = new CoapClient(new URI("coap://192.168.15.170:5683/helloWorld"));
                CoapResponse response = client.post(str, 0);            

            }
            System.out.println("done");         
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }catch (Exception e) {
            e.printStackTrace();
        }

我发送 1000000 记录但发送时首先发送65535条记录并等待几秒钟。等待几秒钟后再次开始发送。

系统详细信息:

操作系统:Win 7 64位。 RAM:4 GM

为什么它会在65535条记录之后等待?

3 个答案:

答案 0 :(得分:0)

我经历了Californium.CoAP每秒收到250条记录。我添加了4 ms的中继,因此它设法发送少于250条记录/秒。

如果您将数据从不同的计算机发送到同一CoAP服务器资源,则需要相应地管理延迟。

CoAP Message Id(MID)ranginf仅限1-65565。

还可以正确配置 Californium.properties

答案 1 :(得分:0)

在我的情况下,每分钟从单个客户端接收的消息超过6万条,减少californium.properties(或NetworkConfig,如果愿意的话)中的EXCHANGE_LIFETIME是有效的。

答案 2 :(得分:0)

只需提一下:
16位CoAP消息ID和默认的交换寿命约为247秒,
导致250 msg / s。因此,这是CoAP RFC7252的默认限制。

EXCHANGE_LIFETIME更改为较低的值可能会导致其他副作用。
实际上,如果在EXCHANGE_LIFETIME之后(意外地)接收到一条消息,则它违反了重复数据删除和/或CON消息的传输。

CoAP并不是真的要从一个power client流数据。因此,我们专注于Californium开发以支持用例,在该用例中,许多客户端以中等速率发送消息,从而导致该例的高吞吐量。

相关问题