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


Java CoapRequestCode類代碼示例

本文整理匯總了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();
                }
    }
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:18,代碼來源:CoAPClient.java

示例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");
		}
	}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:26,代碼來源:WSIAdapterCoapHAI.java

示例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();
    }
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:19,代碼來源:WsiUberDustCon.java

示例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;
}
 
開發者ID:heia-fr,項目名稱:wot_gateways,代碼行數:9,代碼來源:BasicCoapClientChannel.java

示例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;
}
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:9,代碼來源:BasicCoapClientChannel.java

示例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;
	}
 
開發者ID:adityayadav76,項目名稱:internet_of_things_simulator,代碼行數:15,代碼來源:SampleCoAPConnection.java

示例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();
    }
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:28,代碼來源:WsiUberDustCon.java

示例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;
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:8,代碼來源:BasicCoapClientChannel.java

示例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;
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:68,代碼來源:TCSWSIAdapter.java

示例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;
}
 
開發者ID:vitrofp7,項目名稱:vitro,代碼行數:70,代碼來源:WSIAdapterCoap.java

示例11: createRequest

import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public CoapRequest createRequest(boolean reliable, CoapRequestCode requestCode); 
開發者ID:heia-fr,項目名稱:wot_gateways,代碼行數:2,代碼來源:ClientChannel.java

示例12: getRequestCode

import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public CoapRequestCode getRequestCode(); 
開發者ID:heia-fr,項目名稱:wot_gateways,代碼行數:2,代碼來源:CoapRequest.java

示例13: setRequestCode

import org.ws4d.coap.messages.CoapRequestCode; //導入依賴的package包/類
public void setRequestCode(CoapRequestCode requestCode); 
開發者ID:heia-fr,項目名稱:wot_gateways,代碼行數:2,代碼來源:CoapRequest.java


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