package com.eactive.eai.adapter.socket2.app.udpquote;

import com.eactive.eai.adapter.socket2.config.SocketAdapterContext;
import com.eactive.eai.adapter.socket2.config.SocketAdapterFactory;
import com.eactive.eai.adapter.socket2.protocol.IRequestProcessor;
import com.eactive.eai.adapter.socket2.protocol.ISocketAdapter;


public class UdpQuote {
	static public void main(String[] args) throws Exception {
		SocketAdapterContext context = new SocketAdapterContext();
		context.setAdapterGroupName("UdpServerAdapterGroup");
		context.setAdapterName("UdpServerAdapter");
		context.setBoundUsage("INBOUND");
		context.setResponseType("ASYN");
		
//		context.setSocketType("CLIENT");
//		context.setHostName("121.189.63.31");
//		context.setPortNumber(61868); //45517);
//		context.setLocalHostName("10.80.1.181");
//		context.setLocalPortNumber(45517);
		
		context.setSocketType("SERVER");
		context.setHostName("*");
		context.setPortNumber(45517);
		
		context.setProtocol("UDP_FIXED_LENGTH_PAYLOAD");
		context.setSendPayloadLength(63);
		context.setRecvPayloadLength(63);

		context.setTimeout(60);
		context.setMaxConnection(10);
		context.setTraceLevel(context.TRACE_LEVEL_DEBUG);		
		
		context.setRequestProcessor(new IRequestProcessor() {
			public byte[] handle(byte[] request) throws Exception {
//				System.out.println("[" + TimeUtil.formatDate(System.currentTimeMillis()) + 
//						"] <RECV> '" + new String(request) + "'");
				return request;
			}
		});		
		
		ISocketAdapter client = SocketAdapterFactory.createSocketAdapter(context);
		client.start().join();
	}
}
