#####################################
#  BillCom 처리                     # 
#####################################

작성자 : 장형화(hhjang97@venus.uos.ac.kr)
작성일 : 2005. 01. 12
수정일 : 

원본 :
설명 :

BillCom 처리 예제 소스


################################# ################################# #################################

====================== Property.java ============================
public static int BILLCOMM_HEADER_LEN = 108; //헤더의 사이즈
=================================================================


====================== Server.java ============================
boolean isBillCom = true;
String min = "";

/*
 * 데이터 읽기
 */
public void run() {

	int ret = 0;
	
	//	========== 빌컴 헤더 읽기
	System.out.println("========== Read Data ===========");
	if (isBillCom) {

		while (ret < Property.BILLCOMM_HEADER_LEN) {
			ret = dis.read(headerBuf, 0, Property.BILLCOMM_HEADER_LEN);
			if (ret <= 0){
				System.out.println("********* header size is 0....");
				throw new Exception("Header Error 1");
			}
			
			
			if (ret > 0 && ret < Property.BILLCOMM_HEADER_LEN) {
				System.out.println("********* 유효하지 않은 헤더 크기 **********");
				Util.printByte(headerBuf);
				System.out.println("ret = " + ret);

				throw new Exception("Header Error 2");
				//return ;
			}
			
		} // end while


		System.out.println("========== Read BillCom Data End ===========");
		
		// min 추출 : 데이터 전송시 필요함
		min = Util.byteArrayCutString(headerBuf, 44, 16);
		int datasize = getRecvDataSize(headerBuf); 
		if (datasize <= 0){
			System.out.println("received data size is 0....  header only.....");
			throw new Exception("Header Error 3");
		}
		System.out.println("Data Size : " + datasize);
		// 데이타 읽기
		ret = 0;
		ret = dis.read(b, 0, datasize);
	
	} else {
		min = "0000000000000000";
		ret = dis.read(b);
	}
	 
	System.out.println("ret = " + ret);
	
	str = new String(b);
	System.out.println("str = "+ str.trim());
					
} // end run




	/*
	 * 데이터 전송하기
	 */
	public byte[] attachBillHeader(byte[] sendPacket) throws Exception                                                           
	{                                                                                                                            
		try{                                                                                                                      
			sendPacket = Util.addBytes(billHeader(sendPacket.length), sendPacket);                                                 
		}catch(Exception e){                                                                                                      =================================================================
			throw new Exception("BillHeader : 빌컴헤더 생성 오류");                                                                
		}                                                                                                                         
		return sendPacket;                                                                                                        
	}                                                                                                                            
	private byte[] billHeader(int pSize) throws Exception                                                                        
	{                                                                                                                            
		byte[] temp1 = {                                                                                                          
						(byte)0xf0, (byte)0x0f, (byte)0xf0, (byte)0x0f,		//4                                                        
						(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,//12           
						(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,		//16                                                       
						};                                                                                                            
                                                                                                                                
		byte[] minByte = Util.getFixBytes(min, 16);                                                                               
                                                                                                                                
		byte[] temp2 = {                                                                                                          
						(byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, //signal managemenet flag	//36                               
						(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,		//42                               
						(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, //Reserved	//48                      
						};                                                                                                            
		                                                                                                                          
		byte[] sizeByte = Util.writeByteInt(pSize);                                                                               
                                                                                                                                
		byte[] temp3 = {                                                                                                          
						(byte)0x4b, (byte)0x43, (byte)0x53, (byte)0x50		//"KCSP"	//56                                              
						};                                                                                                            
                                                                                                                                
		byte[] billComHeader = Util.addBytes(Util.addBytes(temp1, minByte), Util.addBytes(Util.addBytes(temp2, sizeByte), temp3));
                                                                                                                                
//		Debug.debug(billComHeader);                                                                                               
                                                                                                                                
		return billComHeader;                                                                                                     
	}                                                                                                                            
	public void SendMsg(byte[] msg){                                                                                             
		SendMsg(msg, true);                                                                                                       
	}
	public void SendMsg(byte[] msg, boolean outMsg){                                                                             
		try{                                                                                                                      
			String temp = new String(msg);                                                                                         
			if (outMsg) {
				System.out.println("SendMsg = "+temp);
				Util.printByte(msg);
			}                                                                                                                      
			int total_size = msg.length;                                                                                           
			byte[] sendMsg = null;                                                                                                 
			sendMsg = Util.addBytes(Util.writeByteInt(total_size), msg);                                                           
			if (isBillCom) {
				sendMsg = attachBillHeader(sendMsg);
			}
			if (!isTest) {
				dos.write(sendMsg,0,sendMsg.length);
				dos.flush();
			}
		}catch(Exception e){
			System.out.println("==== Message Send Error ====");
			e.printStackTrace();
		}                                                                                                                         
	}

=================================================================





#################################
# 
#################################