2 *******************************************************************
4 * Copyright 2016 Samsung Electronics All Rights Reserved.
6 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.ciserver;
24 import java.net.InetSocketAddress;
25 import java.util.Scanner;
27 import org.iotivity.cloud.base.CoapServer;
28 import org.iotivity.cloud.base.ResourceManager;
29 import org.iotivity.cloud.base.SessionManager;
30 import org.iotivity.cloud.ciserver.protocols.CoapAuthHandler;
31 import org.iotivity.cloud.ciserver.protocols.CoapRelayHandler;
32 import org.iotivity.cloud.ciserver.resources.KeepAliveResource;
33 import org.iotivity.cloud.util.CoapLogHandler;
34 import org.iotivity.cloud.util.Logger;
36 public class CloudInterfaceServer {
38 public static void main(String[] args) throws Exception {
40 System.out.println("-----CI SERVER-------");
42 if (args.length != 5) {
44 "coap server port and RDServer_Address port AccountServer_Address Port required\n"
45 + "ex) 5683 127.0.0.1 5684 127.0.0.1 5685\n");
49 ResourceManager resourceManager = null;
50 SessionManager sessionManager = null;
51 CoapServer coapServer = null;
53 CoapRelayHandler relayHandler = null;
54 CoapAuthHandler authHandler = null;
56 KeepAliveResource keepAliveResource = null;
58 coapServer = new CoapServer();
60 sessionManager = new SessionManager();
62 resourceManager = new ResourceManager();
64 relayHandler = new CoapRelayHandler(sessionManager);
66 authHandler = new CoapAuthHandler();
68 keepAliveResource = new KeepAliveResource(sessionManager,
69 new int[] { 1, 2, 4, 8 });
71 coapServer.addHandler(new CoapLogHandler());
73 coapServer.addHandler(authHandler);
75 coapServer.addHandler(relayHandler);
77 coapServer.addHandler(resourceManager);
79 resourceManager.registerResource(keepAliveResource);
81 authHandler.startHandler(args[3], Integer.parseInt(args[4]));
83 relayHandler.startHandler(args[1], Integer.parseInt(args[2]), args[3],
84 Integer.parseInt(args[4]));
87 .startServer(new InetSocketAddress(Integer.parseInt(args[0])));
89 keepAliveResource.startSessionChecker();
91 Scanner in = new Scanner(System.in, "UTF-8");
93 System.out.println("press 'q' to terminate");
95 while (!in.nextLine().equals("q"));
99 System.out.println("Terminating...");
101 keepAliveResource.stopSessionChecker();
103 coapServer.stopServer();
105 relayHandler.stopHandler();
107 authHandler.stopHandler();
109 System.out.println("Terminated");