org.bdware.dogp.sample.TestDOIPOverDOGPMain Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of doip-audit-tool Show documentation
Show all versions of doip-audit-tool Show documentation
doip audit tool developed by bdware
The 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();
}
}