#####################################
#  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();
		}                                                                                                                         
	}

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





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