当前位置: 首页>>代码示例>>Java>>正文


Java CoapBlockOption类代码示例

本文整理汇总了Java中org.ws4d.coap.messages.CoapBlockOption的典型用法代码示例。如果您正苦于以下问题:Java CoapBlockOption类的具体用法?Java CoapBlockOption怎么用?Java CoapBlockOption使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CoapBlockOption类属于org.ws4d.coap.messages包,在下文中一共展示了CoapBlockOption类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addBlock

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
public boolean addBlock(CoapMessage msg, CoapBlockOption block){
 		int blockPos = block.getBytePosition();
 		int blockLength =  msg.getPayloadLength();
 		int bufSize = payload.size();
 		
 		/*TODO: check if payload length = blocksize (except for the last block)*/
 		if (blockPos > bufSize){
 			/* data is missing before this block */
 			return false;
 		} else if ((blockPos + blockLength) <= bufSize){
	/* data already received */
 			return false;
}
 		int offset = bufSize - blockPos;
 		payload.write(msg.getPayload(), offset, blockLength - offset);
 		
 		if (block.isLast()){
 			/* was this the last block */
 			finished = true;
 		}
 		
 		return true;
 	}
 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:24,代码来源:BasicCoapClientChannel.java

示例2: ClientBlockContext

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
public ClientBlockContext(CoapBlockOption blockOption, CoapBlockSize maxBlocksize) {
	
	/* determine the right blocksize (min of remote and max)*/
	if (maxBlocksize == null){
		blockSize = blockOption.getBlockSize();
	} else {
		int max = maxBlocksize.getSize();
		int remote = blockOption.getBlockSize().getSize();
		if (remote < max){
			blockSize = blockOption.getBlockSize();
		} else {
			blockSize = maxBlocksize;
		}
	}
}
 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:16,代码来源:BasicCoapClientChannel.java

示例3: handleMessage

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的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

示例4: getNextBlock

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
public CoapBlockOption getNextBlock() {
	int num = payload.size() / blockSize.getSize(); //ignore the rest (no rest should be there)
	return new CoapBlockOption(num, false, blockSize);
}
 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:5,代码来源:BasicCoapClientChannel.java

示例5: handleMessage

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的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

示例6: handleMessage

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的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

示例7: getBlock1

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
CoapBlockOption getBlock1(); 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:2,代码来源:CoapMessage.java

示例8: setBlock1

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
void setBlock1(CoapBlockOption blockOption); 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:2,代码来源:CoapMessage.java

示例9: getBlock2

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
CoapBlockOption getBlock2(); 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:2,代码来源:CoapMessage.java

示例10: setBlock2

import org.ws4d.coap.messages.CoapBlockOption; //导入依赖的package包/类
void setBlock2(CoapBlockOption blockOption); 
开发者ID:heia-fr,项目名称:wot_gateways,代码行数:2,代码来源:CoapMessage.java


注:本文中的org.ws4d.coap.messages.CoapBlockOption类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。