我使用 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条记录时,它会等待很少的seconds.after等待几秒钟,然后再次开始发送。
系统详细信息:
操作系统:赢7 64位。拉姆:4通用汽车
为什么要等到65535张唱片之后?
发布于 2015-04-02 04:57:24
我浏览了Californium.CoAP,每秒接收250个记录。我增加了4 ms.so的中继,它设法发送少于250条记录/秒。
如果您将数据从不同的计算机发送到同一CoAP服务器资源,则需要相应地管理延迟。
CoAP消息Id (MID)范围仅为1-65565。
还可以正确地配置Californium.properties以使其工作。
发布于 2019-08-10 07:15:45
我只想提一下:
16位CoAP消息ID和默认的交换生存期约247秒,
因此,这是CoAP RFC7252的默认限制。
若要将该EXCHANGE_LIFETIME更改为较低的值,则可能会产生其他副作用。
实际上,如果消息在该EXCHANGE_LIFETIME之后被(意外地)重新接收,它就违反了去重复和/或CON消息传输。
CoAP并不真正用于从一个power client中流数据。因此,我们专注于加利福尼亚的开发,以支持用例,其中许多客户端以适中的速率发送消息,从而为该案例提供了较高的吞吐量。
发布于 2019-08-06 04:54:05
在我的例子中,每分钟从单个客户端接收超过60k条消息,减少EXCHANGE_LIFETIME中的californium.properties(或者如果您愿意的话是NetworkConfig )是有效的。
https://stackoverflow.com/questions/29388064
复制相似问题