1

CoAPプロトコルを使用してデータを送信するために、Californium API ( https://github.com/eclipse/californium ) を使用しています。

以下は、クライアントとサーバーの両方のスニペットです。

サーバー:

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 レコードを送信し、数秒間待機します。数秒間待機した後、再び送信を開始します。

システムの詳細:

OS:Win7 64ビット。RAM:4GM

65535 レコード後に待機するのはなぜですか?

4

3 に答える 3

0

Californium.CoAP は 1 秒あたり 250 レコードを受信します。4 ミリ秒のリレーを追加して、1 秒あたり 250 レコード未満を送信できるようにしました。

別のマシンから同じ CoAP サーバー リソースにデータを送信する場合は、それに応じて遅延を管理する必要があります。

CoAP メッセージ ID (MID) の範囲は 1 ~ 65565 のみです。

また、 Californium.propertiesが機能するように適切に構成します。

于 2015-04-02T04:57:24.230 に答える
0

私の場合、1 つのクライアントから 1 分間に 60,000 件を超えるメッセージを受信した場合、californium.properties (または必要に応じて NetworkConfig) の EXCHANGE_LIFETIME を減らすことが効果的でした。

于 2019-08-06T04:54:05.130 に答える