本文整理匯總了Java中org.ws4d.coap.messages.CoapRequestCode類的典型用法代碼示例。如果您正苦於以下問題:Java CoapRequestCode類的具體用法?Java CoapRequestCode怎麽用?Java CoapRequestCode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CoapRequestCode類屬於org.ws4d.coap.messages包,在下文中一共展示了CoapRequestCode類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: runTestClient
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public void runTestClient(){
try {
clientChannel = channelManager.connect(this, InetAddress.getByName(SERVER_ADDRESS), PORT);
CoapRequest coapRequest = clientChannel.createRequest(true, CoapRequestCode.GET);
// coapRequest.setContentType(CoapMediaType.octet_stream);
// coapRequest.setToken("ABCD".getBytes());
// coapRequest.setUriHost("123.123.123.123");
// coapRequest.setUriPort(1234);
// coapRequest.setUriPath("/sub1/sub2/sub3/");
// coapRequest.setUriQuery("a=1&b=2&c=3");
// coapRequest.setProxyUri("http://proxy.org:1234/proxytest");
clientChannel.sendMessage(coapRequest);
System.out.println("Sent Request");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
示例2: coapObservationRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
private void coapObservationRequest(Node node, Resource resource) throws UnknownHostException, VitroGatewayException {
//String proxyAddress = getProxyAddress(node);
//if(proxyAddress != null) {
if(clientChannel != null) {
String moteUriResource = "";
if(MoteResource.containsValue(resource)) {
moteUriResource += MoteResource.getMoteUriResource(resource);
//clientChannel = channelManager.connect(this, InetAddress.getByName(proxyAddress), PORT);
// clientChannel = channelManager.connect(this, InetAddress.getByName("localhost"), PORT);
CoapRequest coapRequest = clientChannel.createRequest(true, CoapRequestCode.GET);
coapRequest.setProxyUri("coap://[" + node.getId() + "]:61616/" + moteUriResource);
// coapRequest.setUriPath(moteUriResource);
clientChannel.sendMessage(coapRequest);
logger.info("Sent Request: " + coapRequest.toString());
} else {
logger.warn("No resource mapping for Node " + node.getId() + " and Resource " + resource.getName());
throw new WSIAdapterException("No resource mapping for Node " + node.getId() + " and Resource " + resource.getName());
}
//
} else {
logger.warn("No available proxy for Node " + node.getId() + " is found");
throw new WSIAdapterException("No available proxy for Node " + node.getId() + " is found");
}
}
示例3: coapSetActuatorValue
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public void coapSetActuatorValue(int onOff, String nodeurn, String justtheCapName) {
try {
clientChannel = channelManager.connect(this, InetAddress.getByName(SERVER_ADDRESS_POST), PORT);
String hexNodeAddr = nodeurn.substring(staticprefixNode.length());
hexNodeAddr = hexNodeAddr.substring("0x".length());
CoapRequest coapRequest = clientChannel.createRequest(true, CoapRequestCode.POST);
coapRequest.setPayload(Integer.toString(onOff));
//coapRequest.setUriPath("/"+nodeurn + "/"+ fullUrnUberdustCapName); //no longer used.
coapRequest.setUriHost(hexNodeAddr);
coapRequest.setUriPath("/"+justtheCapName);
clientChannel.sendMessage(coapRequest);
//logger.debug("Sent Request for setting value of " +nodeurn+ " cap: "+justtheCapName+ " to: "+Integer.toString(onOff) + " MessageId: " + Integer.toString(coapRequest.getMessageID()) );
// TODO: the server will send back a response with the changed value here! We could use it as well (?)
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
示例4: createRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
@Override
public BasicCoapRequest createRequest(boolean reliable, CoapRequestCode requestCode) {
BasicCoapRequest msg = new BasicCoapRequest(
reliable ? CoapPacketType.CON : CoapPacketType.NON, requestCode,
((ClientChannelManager) channelManager).getNewMessageID());
msg.setChannel(this);
return msg;
}
示例5: createRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
@Override
public BasicCoapRequest createRequest(boolean reliable, CoapRequestCode requestCode) {
BasicCoapRequest msg = new BasicCoapRequest(
reliable ? CoapPacketType.CON : CoapPacketType.NON, requestCode,
channelManager.getNewMessageID());
msg.setChannel(this);
return msg;
}
示例6: send
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
@Override
public Object send(Object arg0) throws Exception {
CoapRequest coapRequest = clientChannel.createRequest(true, CoapRequestCode.GET);
// coapRequest.setContentType(CoapMediaType.octet_stream);
// coapRequest.setToken("ABCD".getBytes());
// coapRequest.setUriHost("123.123.123.123");
// coapRequest.setUriPort(1234);
// coapRequest.setUriPath("/sub1/sub2/sub3/");
// coapRequest.setUriQuery("a=1&b=2&c=3");
// coapRequest.setProxyUri("http://proxy.org:1234/proxytest");
clientChannel.sendMessage(coapRequest);
System.out.println("Sent Request");
return null;
}
示例7: coapGetActuatorStatus
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public void coapGetActuatorStatus(String nodeurn, String justtheCapName){
try {
// 1. get hex addr for nodeurn
// 2. get simple capabilityUrn
String hexNodeAddr = nodeurn.substring(staticprefixNode.length());
hexNodeAddr = hexNodeAddr.substring("0x".length());
clientChannel = channelManager.connect(this, InetAddress.getByName(SERVER_ADDRESS_STATUS), PORT);
CoapRequest coapRequest = clientChannel.createRequest(true, CoapRequestCode.GET);
// coapRequest.setContentType(CoapMediaType.octet_stream);
// coapRequest.setToken("ABCD".getBytes());
coapRequest.setUriHost(hexNodeAddr);
// coapRequest.setUriPort(1234);
coapRequest.setUriPath("/"+justtheCapName);
// coapRequest.setUriQuery("a=1&b=2&c=3");
// coapRequest.setProxyUri("http://proxy.org:1234/proxytest");
clientChannel.sendMessage(coapRequest);
//logger.debug("uriHost:" +coapRequest.getUriHost() ) ;
//logger.debug("uriPath:" +coapRequest.getUriPath() ) ;
//logger.debug("clientChannel:" +clientChannel.getRemoteAddress().getHostAddress() +"::"+ Integer.toString(clientChannel.getRemotePort())) ;
//logger.debug("Sent Request. MessageId: " + Integer.toString(coapRequest.getMessageID()) );
coapRequestMessageIdToUrnNode.put(Integer.toString(coapRequest.getMessageID()), nodeurn+"::"+justtheCapName);
//urnNodeToCoapReply.put(nodeurn+"status", "");
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
示例8: createRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public BasicCoapRequest createRequest(boolean reliable, CoapRequestCode requestCode) {
BasicCoapRequest msg = new BasicCoapRequest(
reliable ? CoapPacketType.CON : CoapPacketType.NON, requestCode,
channelManager.getNewMessageID());
msg.setChannel(this);
return msg;
}
示例9: coapResourcesRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
private int coapResourcesRequest(Node node) throws UnknownHostException, WSIAdapterException {
int messageIDToReturn = UNDEFINED_COAP_MESSAGE_ID;
String proxyAddress = getProxyAddress(node);
if(proxyAddress != null) {
// 15/04
CoapClientChannel clientChannelResources = null;
try {
// *** Alternative approach
if(!proxyAddrToClientChannelResourcesHM.isEmpty()
&&proxyAddrToClientChannelResourcesHM.containsKey(proxyAddress)
&& proxyAddrToClientChannelResourcesHM.get(proxyAddress)!= null)
{
//re use it.
clientChannelResources= proxyAddrToClientChannelResourcesHM.get(proxyAddress);
} else {
clientChannelResources = channelManager.connect((CoapClient)this, InetAddress.getByName(proxyAddress), PORT);
if(clientChannelResources!=null)
{
proxyAddrToClientChannelResourcesHM.put(proxyAddress, clientChannelResources);
}
else {
logger.error("Impossible to setup a coap channel for resources!");
return UNDEFINED_COAP_MESSAGE_ID;
}
}
// *** end of alternative approach
// == Fix that was still causing too many open files:
//if(clientChannelResources!= null) {
// clientChannelResources.close();
//}
//clientChannelResources = channelManager.connect((CoapClient)this, InetAddress.getByName(proxyAddress), PORT);
// == end of fix
// clientChannelResources = channelManager.connect(this, InetAddress.getByName("localhost"), PORT);
CoapRequest coapRequest = clientChannelResources.createRequest(true, CoapRequestCode.GET);
//coapRequest.setContentType(CoapMediaType.octet_stream);
//coapRequest.setProxyUri("coap://[" + node.getId() + "]:5683/" + MoteResource.RESOURCE_DISCOVERY);
System.out.println("Il nodo da contattare è "+node.getId());
coapRequest.setUriHost(node.getId());
coapRequest.setUriPort(5683);
coapRequest.setUriPath(MoteResource.RESOURCE_DISCOVERY);
clientChannelResources.sendMessage(coapRequest);
messageIDToReturn = coapRequest.getMessageID();
logger.info("Sent Request: {} for node {}", coapRequest.toString(), node.getId());
//clientChannelResources.close();
}
catch(Exception ex) {
if(clientChannelResources!=null)
{
// clientChannelResources.close();
}
throw new WSIAdapterException("Unable to send coap resource req to " + node.getId());
}
finally {
if(clientChannelResources !=null)
{
// clientChannelResources.close();
}
}
} else {
logger.warn("No available proxy for Node " + node.getId() + " is found");
throw new WSIAdapterException("No available proxy for Node " + node.getId() + " is found");
}
return messageIDToReturn;
}
示例10: coapResourcesRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
/**
* Private CoAP methods
*/
private int coapResourcesRequest(Node node) throws UnknownHostException, WSIAdapterException {
int messageIDToReturn = UNDEFINED_COAP_MESSAGE_ID;
String proxyAddress = getProxyAddress(node);
if(proxyAddress != null) {
// 15/04
CoapClientChannel clientChannelResources = null;
try{
// *** Alternative approach
if(!proxyAddrToClientChannelResourcesHM.isEmpty()
&&proxyAddrToClientChannelResourcesHM.containsKey(proxyAddress)
&& proxyAddrToClientChannelResourcesHM.get(proxyAddress)!= null)
{
//re use it.
clientChannelResources= proxyAddrToClientChannelResourcesHM.get(proxyAddress);
} else {
clientChannelResources = channelManager.connect((CoapClient)this, InetAddress.getByName(proxyAddress), COAP_PORT);
if(clientChannelResources!=null)
{
proxyAddrToClientChannelResourcesHM.put(proxyAddress, clientChannelResources);
}
else {
logger.error("Impossible to setup a coap channel for resources!");
return UNDEFINED_COAP_MESSAGE_ID;
}
}
// *** end of alternative approach
// == Fix that was still causing too many open files:
//if(clientChannelResources!= null) {
// clientChannelResources.close();
//}
//clientChannelResources = channelManager.connect(this, InetAddress.getByName(proxyAddress), COAP_PORT);
// == end of fix
//
// clientChannelResources = channelManager.connect(this, InetAddress.getByName("localhost"), PORT);
CoapRequest coapRequest = clientChannelResources.createRequest(true, CoapRequestCode.GET);
coapRequest.setProxyUri("coap://[" + node.getId() + "]:61616/" + MoteResource.RESOURCE_DISCOVERY);
// coapRequest.setUriPath("/" + MoteResource.RESOURCE_DISCOVERY);
clientChannelResources.sendMessage(coapRequest);
messageIDToReturn = coapRequest.getMessageID();
logger.info("Sent Request: {} for node {}", coapRequest.toString(), node.getId());
//clientChannelResources.close();
}
catch(Exception ex) {
logger.error("Could not setup a coap channel or send the coapResourcesRequest message!", ex);
if(clientChannelResources !=null)
{
// clientChannelResources.close();
}
throw new WSIAdapterException("Unable to send coap resource req to " + node.getId());
}
finally {
if(clientChannelResources !=null)
{
// clientChannelResources.close();
}
}
} else {
logger.warn("No available proxy for Node " + node.getId() + " is found");
throw new WSIAdapterException("No available proxy for Node " + node.getId() + " is found");
}
return messageIDToReturn;
}
示例11: createRequest
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public CoapRequest createRequest(boolean reliable, CoapRequestCode requestCode);
示例12: getRequestCode
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public CoapRequestCode getRequestCode();
示例13: setRequestCode
import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public void setRequestCode(CoapRequestCode requestCode);