當前位置: 首頁>>代碼示例>>Java>>正文


Java CoapEmptyMessage類代碼示例

本文整理匯總了Java中org.ws4d.coap.messages.CoapEmptyMessage的典型用法代碼示例。如果您正苦於以下問題:Java CoapEmptyMessage類的具體用法?Java CoapEmptyMessage怎麽用?Java CoapEmptyMessage使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CoapEmptyMessage類屬於org.ws4d.coap.messages包,在下文中一共展示了CoapEmptyMessage類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleMessage

import org.ws4d.coap.messages.CoapEmptyMessage; //導入依賴的package包/類
@Override 
public void handleMessage(CoapMessage message) { 
	if (message.isRequest()){
		/* this is a client channel, no requests allowed */
		message.getChannel().sendMessage(new CoapEmptyMessage(CoapPacketType.RST, message.getMessageID()));
		return;
	}
	
	if (message.isEmpty() && message.getPacketType() == CoapPacketType.ACK){
		/* this is the ACK of a separate response */
		//TODO: implement a handler or listener, that informs a client when a sep. resp. ack was received
		return;
	}  
	
	if (message.getPacketType() == CoapPacketType.CON) {
		/* this is a separate response */
		/* send ACK */
		this.sendMessage(new CoapEmptyMessage(CoapPacketType.ACK, message.getMessageID()));
	} 
	
	/* check for blockwise transfer */
	CoapBlockOption block2 = message.getBlock2();
	if (blockContext == null && block2 != null){
		/* initiate blockwise transfer */
		blockContext = new ClientBlockContext(block2, maxReceiveBlocksize);
		blockContext.setFirstRequest(lastRequest);
		blockContext.setFirstResponse((CoapResponse) message);
	}
	
	if (blockContext!= null){
		/*blocking option*/
		if (!blockContext.addBlock(message, block2)){
			/*this was not a correct block*/
			/* TODO: implement either a RST or ignore this packet */
		}
		
		if (!blockContext.isFinished()){
			/* TODO: implement a counter to avoid an infinity req/resp loop:
			 *  		if the same block is received more than x times -> rst the connection 
			 *  implement maxPayloadSize to avoid an infinity payload */
			CoapBlockOption newBlock = blockContext.getNextBlock();
			if (lastRequest == null){
				/*TODO: this should never happen*/
				System.out.println("ERROR: client channel: lastRequest == null");
			} else {
				/* create a new request for the next block */
				BasicCoapRequest request =  new BasicCoapRequest(lastRequest.getPacketType(), lastRequest.getRequestCode(), ((ClientChannelManager) channelManager).getNewMessageID());
				request.copyHeaderOptions((BasicCoapRequest) blockContext.getFirstRequest()); 
				request.setBlock2(newBlock);
				sendMessage(request);
			}
			/* TODO: implement handler, inform the client that a block (but not the complete message) was received*/
			return;
		} 
		/* blockwise transfer finished */
		message.setPayload(blockContext.getPayload());
		/* TODO: give the payload separately and leave the original message as they is*/
	} 		

	/* normal or separate response */
	client.onResponse(this, (BasicCoapResponse) message);
}
 
開發者ID:heia-fr,項目名稱:wot_gateways,代碼行數:63,代碼來源:BasicCoapClientChannel.java

示例2: handleMessage

import org.ws4d.coap.messages.CoapEmptyMessage; //導入依賴的package包/類
@Override 
public void handleMessage(CoapMessage message) { 
	if (message.isRequest()){
		/* this is a client channel, no requests allowed */
		message.getChannel().sendMessage(new CoapEmptyMessage(CoapPacketType.RST, message.getMessageID()));
		return;
	}
	
	if (message.isEmpty() && message.getPacketType() == CoapPacketType.ACK){
		/* this is the ACK of a separate response */
		//TODO: implement a handler or listener, that informs a client when a sep. resp. ack was received
		return;
	}  
	
	if (message.getPacketType() == CoapPacketType.CON) {
		/* this is a separate response */
		/* send ACK */
		this.sendMessage(new CoapEmptyMessage(CoapPacketType.ACK, message.getMessageID()));
	} 
	
	/* check for blockwise transfer */
	CoapBlockOption block2 = message.getBlock2();
	if (blockContext == null && block2 != null){
		/* initiate blockwise transfer */
		blockContext = new ClientBlockContext(block2, maxReceiveBlocksize);
		blockContext.setFirstRequest(lastRequest);
		blockContext.setFirstResponse((CoapResponse) message);
	}
	
	if (blockContext!= null){
		/*blocking option*/
		if (!blockContext.addBlock(message, block2)){
			/*this was not a correct block*/
			/* TODO: implement either a RST or ignore this packet */
		}
		
		if (!blockContext.isFinished()){
			/* TODO: implement a counter to avoid an infinity req/resp loop:
			 *  		if the same block is received more than x times -> rst the connection 
			 *  implement maxPayloadSize to avoid an infinity payload */
			CoapBlockOption newBlock = blockContext.getNextBlock();
			if (lastRequest == null){
				/*TODO: this should never happen*/
				System.out.println("ERROR: client channel: lastRequest == null");
			} else {
				/* create a new request for the next block */
				BasicCoapRequest request =  new BasicCoapRequest(lastRequest.getPacketType(), lastRequest.getRequestCode(), channelManager.getNewMessageID());
				request.copyHeaderOptions((BasicCoapRequest) blockContext.getFirstRequest()); 
				request.setBlock2(newBlock);
				sendMessage(request);
			}
			/* TODO: implement handler, inform the client that a block (but not the complete message) was received*/
			return;
		} 
		/* blockwise transfer finished */
		message.setPayload(blockContext.getPayload());
		/* TODO: give the payload separately and leave the original message as they is*/
	} 		

	/* normal or separate response */
	client.onResponse(this, (BasicCoapResponse) message);
}
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:63,代碼來源:BasicCoapClientChannel.java

示例3: onSeparateResponseAck

import org.ws4d.coap.messages.CoapEmptyMessage; //導入依賴的package包/類
public void onSeparateResponseAck(CoapClientChannel channel, CoapEmptyMessage message) {
	logger.info("Received Ack of Separate Response");
	//TODO: no implementation in TinyOS
       // signal.countDown(); //commented out because the message will timeout.
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:6,代碼來源:WSIAdapterCoapHAI.java

示例4: onSeparateResponseAck

import org.ws4d.coap.messages.CoapEmptyMessage; //導入依賴的package包/類
public void onSeparateResponseAck(CoapClientChannel coapClientChannel, CoapEmptyMessage coapEmptyMessage) {
    //To change body of implemented methods use File | Settings | File Templates.
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:4,代碼來源:WsiUberDustCon.java

示例5: handleMessage

import org.ws4d.coap.messages.CoapEmptyMessage; //導入依賴的package包/類
public void handleMessage(CoapMessage message) { 
	if (message.isRequest()){
		/* this is a client channel, no requests allowed */
		message.getChannel().sendMessage(new CoapEmptyMessage(CoapPacketType.RST, message.getMessageID()));
		return;
	}
	
	if (message.isEmpty() && message.getPacketType() == CoapPacketType.ACK){
		/* this is the ACK of a separate response */
		//TODO: implement a handler or listener, that informs a client when a sep. resp. ack was received
		return;
	}  
	
	if (message.getPacketType() == CoapPacketType.CON) {
		/* this is a separate response */
		/* send ACK */
		this.sendMessage(new CoapEmptyMessage(CoapPacketType.ACK, message.getMessageID()));
	} 
	
	/* check for blockwise transfer */
	CoapBlockOption block2 = message.getBlock2();
	if (blockContext == null && block2 != null){
		/* initiate blockwise transfer */
		blockContext = new ClientBlockContext(block2, maxReceiveBlocksize);
		blockContext.setFirstRequest(lastRequest);
		blockContext.setFirstResponse((CoapResponse) message);
	}
	
	if (blockContext!= null){
		/*blocking option*/
		if (!blockContext.addBlock(message, block2)){
			/*this was not a correct block*/
			/* TODO: implement either a RST or ignore this packet */
		}
		
		if (!blockContext.isFinished()){
			/* TODO: implement a counter to avoid an infinity req/resp loop:
			 *  		if the same block is received more than x times -> rst the connection 
			 *  implement maxPayloadSize to avoid an infinity payload */
			CoapBlockOption newBlock = blockContext.getNextBlock();
			if (lastRequest == null){
				/*TODO: this should never happen*/
				System.out.println("ERROR: client channel: lastRequest == null");
			} else {
				/* create a new request for the next block */
				BasicCoapRequest request =  new BasicCoapRequest(lastRequest.getPacketType(), lastRequest.getRequestCode(), channelManager.getNewMessageID());
				request.copyHeaderOptions((BasicCoapRequest) blockContext.getFirstRequest()); 
				request.setBlock2(newBlock);
				sendMessage(request);
			}
			/* TODO: implement handler, inform the client that a block (but not the complete message) was received*/
			return;
		} 
		/* blockwise transfer finished */
		message.setPayload(blockContext.getPayload());
		/* TODO: give the payload separately and leave the original message as they is*/
	} 		

	/* normal or separate response */
	client.onResponse(this, (BasicCoapResponse) message);
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:62,代碼來源:BasicCoapClientChannel.java


注:本文中的org.ws4d.coap.messages.CoapEmptyMessage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。