All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bdware.dogp.sample.TestDOIPOverDOGPMain Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
package org.bdware.dogp.sample;

import io.netty.channel.ChannelHandlerContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.dogp.NettyUDPDOGPListener;
import org.bdware.doip.codec.doipMessage.DoipMessage;
import org.bdware.doip.codec.doipMessage.DoipMessageFactory;
import org.bdware.doip.codec.doipMessage.DoipResponseCode;
import org.bdware.doip.endpoint.server.DoipListenerConfig;
import org.bdware.doip.endpoint.server.DoipRequestHandler;

import java.util.concurrent.atomic.AtomicInteger;

public class TestDOIPOverDOGPMain {
    static Logger LOGGER = LogManager.getLogger(TestDOIPOverDOGPMain.class);

    public static void main(String[] args) throws Exception {
        LOGGER.info("USAGE: java -cp doip-audit.jar org.bdware.dogp.sample.TestDOIPOverDOGPMain [port] \n\t\tin default, port=21034");
        AtomicInteger i = new AtomicInteger(0);
        int port = 21034;
        if (args.length > 0) port = Integer.valueOf(args[0]);
        DoipListenerConfig config = new DoipListenerConfig("udpdogp://127.0.0.1:" + port, "2.1").setDebugPrint(false);
        NettyUDPDOGPListener listener = new NettyUDPDOGPListener(21034, config, true);
        RecvCounter counter = new RecvCounter("TestDOIPOverDOGPMain.class");
        counter.start();
        listener.setRequestHandler(new DoipRequestHandler() {
            @Override
            public DoipMessage onRequest(ChannelHandlerContext ctx, DoipMessage msg) {
                DoipMessageFactory.DoipMessageBuilder builder = new DoipMessageFactory.DoipMessageBuilder();
                builder.createResponse(DoipResponseCode.Success, msg);
                builder.setBody("Heeeee!".getBytes());
                counter.inc();
                return builder.create();
            }
        });

        listener.start();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy