Kaynağa Gözat

dev centercomm

shjung 2 yıl önce
ebeveyn
işleme
1ff7258e24

+ 12 - 82
src/main/java/com/its/op/service/its/vds/VdsControlService.java

@@ -2,6 +2,7 @@ package com.its.op.service.its.vds;
 
 import com.its.op.config.VdsServerConfig;
 import com.its.op.dto.its.vds.VdsControlDto;
+import com.its.op.service.its.xprotocol.CenterProtocol;
 import com.its.utils.SysUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -23,8 +24,6 @@ import java.util.concurrent.*;
 @Service
 public class VdsControlService {
 
-    //private final VdsCommClientService vdsCommClientService;
-    //private final TbVdsCtlrRepository repo;
     private final VdsServerConfig vdsServerConfig;
 
     private static final int[] crc16_arc = {
@@ -79,36 +78,6 @@ public class VdsControlService {
         return crc & 0xFFFF;
     }
 
-
-//    // 데이터 1건 조회, 없으면 exception
-//    private TbVdsCtlr requireOne(String id) throws NoSuchElementException {
-//        Optional<TbVdsCtlr> info = this.repo.findById(id);
-//        if (info.isPresent()) {
-//            return info.get();
-//        }
-//        else {
-//            throw new NoSuchElementException("데이터가 존재하지 않습니다: " + id);
-//        }
-////        return this.repo.findOne(id)
-////                .orElseThrow(() -> new NoSuchElementException("데이터가 존재하지 않습니다: " + id));
-//    }
-
-    public byte[] getCenterPacket(byte opCode, int length) {
-
-        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
-        byteBuffer.order(ByteOrder.BIG_ENDIAN);
-        byteBuffer.put((byte)0x24); // 송신시스템-운영단말
-        byteBuffer.put((byte)0x04); // 수신시스템-VDS 서버
-        byteBuffer.put((byte)0x01); // 전체프레임개수
-        byteBuffer.put((byte)0x01); // 현재프레임번호
-        byteBuffer.put((byte)0x00); // Reserved
-        byteBuffer.put(opCode);     // OP Code
-        byteBuffer.putInt(length);  // 데이터 길이
-
-        //log.error("HEAD: {}", SysUtils.byteArrayToHex(byteBuffer.array()));
-        return byteBuffer.array();
-    }
-
     /**
      * VDS Center Communication protocol buffer create
      * @param opCode : opcode
@@ -130,7 +99,7 @@ public class VdsControlService {
         }
 
         // Center packet
-        byte[] center = getCenterPacket(opCode, length);
+        byte[] center = CenterProtocol.getRequestHead(CenterProtocol.INT_ID_VDS_OPER, CenterProtocol.INT_ID_VDS_SERVER, opCode, length);
 
         // VDS  packet
         ByteBuffer vdsBuffer = ByteBuffer.allocate(length);
@@ -200,15 +169,12 @@ public class VdsControlService {
 
         String ipAddress = this.vdsServerConfig.getIpAddress();
         int port = this.vdsServerConfig.getPort();
-        int connectTimeout = 3000; // milli-seconds
+        int connTimeout = 3000; // milli-seconds
         int readTimeout = 2000; // milli-seconds
-        SocketAddress socketAddress = new InetSocketAddress(ipAddress, port);
+
         Socket socket = null;
         try {
-            socket = new Socket();
-            socket.setSoTimeout(readTimeout);			    /* InputStream 에서 데이터읽을때의 timeout */
-            socket.connect(socketAddress, connectTimeout);  /* socket 연결 자체에대한 timeout */
-
+            socket = CenterProtocol.connectServer(ipAddress, port, connTimeout, readTimeout);
             try {
                 byte[] data = cmdBuffer.array();
                 OutputStream os = socket.getOutputStream();
@@ -217,7 +183,7 @@ public class VdsControlService {
                 InputStream recvStream = socket.getInputStream();
                 try {
                     while (true) {
-                        byte[] head = receiveBytes(recvStream, 10);
+                        byte[] head = CenterProtocol.receiveBytes(recvStream, 10);
                         if (head[0] == (byte)0x24 && head[1] == (byte)0x04 && head[5] == (byte)0x0C) {
                             log.info("RECV RESPONSE HEAD: 10 Bytes. {}", SysUtils.byteArrayToHex(head));
                             if (head[4] == (byte) 0xFF) {
@@ -246,7 +212,8 @@ public class VdsControlService {
             String errMsg = "[VDS 서버: " + ipAddress + "." + port + "]";
             result.setResult(2, "VDS 서버와 통신이 실패하였습니다.\r\n" + errMsg);
             return result;
-        } finally {
+        }
+        finally {
             try {
                 if (socket != null) {
                     socket.close();
@@ -327,7 +294,7 @@ public class VdsControlService {
                     while (true) {
                         // 이미지 헤더를 읽을 때 까지 헤더 크기 만큼 데이터 수신
                         // 상태 정보(ACK) 등이 수신될수 있다.
-                        byte[] head = receiveBytes(recvStream, 10);
+                        byte[] head = CenterProtocol.receiveBytes(recvStream, 10);
                         if (head[0] == (byte)0x24 && head[1] == (byte)0x04 && head[5] == (byte)0x16) {
                             log.info("RECV RESPONSE HEAD: 10 Bytes. {}", SysUtils.byteArrayToHex(head));
                             if (head[4] == (byte)0xFF) {
@@ -342,12 +309,12 @@ public class VdsControlService {
                             log.info("RECV IMAGE HEAD  FIRST: 10 Bytes. {}", SysUtils.byteArrayToHex(head));
 
                             int imageHeaderRemainLength = 172;  // 이미지 헤더 사이즈 만큼 더 읽어야 함
-                            byte[] imageHead = receiveBytes(recvStream, imageHeaderRemainLength);
+                            byte[] imageHead = CenterProtocol.receiveBytes(recvStream, imageHeaderRemainLength);
                             int imageSize = SysUtils.bytesToInt(imageHead, 159, ByteOrder.BIG_ENDIAN);
                             log.info("RECV IMAGE HEAD SECOND: 172 Bytes. Image Size: {} Bytes.", imageSize);
                             if (imageSize > 0) {
                                 // 이미지 사이즈 만큼 이미지 데이터를 읽어온다.
-                                byte[] imageArr = receiveBytes(recvStream, imageSize);
+                                byte[] imageArr = CenterProtocol.receiveBytes(recvStream, imageSize);
                                 String imageString = Base64.getEncoder().encodeToString(imageArr);
                                 result.setImage(imageString);
                                 result.setResult(0, "VDS 서버로 부터 정지영상 이미지를 정상적으로 수신하였습니다.");
@@ -359,7 +326,7 @@ public class VdsControlService {
                             int dataSize = SysUtils.bytesToInt(head, 6, ByteOrder.BIG_ENDIAN);
                             log.info("RECV HEAD: 10 Bytes, Data {} Bytes Remain. {}", dataSize, SysUtils.byteArrayToHex(head));
                             if (dataSize > 0) {
-                                byte[] data = receiveBytes(recvStream, dataSize);
+                                byte[] data = CenterProtocol.receiveBytes(recvStream, dataSize);
                                 log.info("RECV DATA: {} Data Bytes. {}", dataSize, SysUtils.byteArrayToHex(data));
                             }
                         }
@@ -402,41 +369,4 @@ public class VdsControlService {
         return result;
     }
 
-    /**
-     * 소켓 입력 버퍼로 부터 데이터 길이만큼 읽어 온다
-     * @param inStream
-     * @param buffSize
-     * @return
-     * @throws IOException
-     */
-    public byte[] receiveBytes(InputStream inStream, int buffSize) throws IOException {
-        byte[] buffer;
-        int bytesRead = 0;
-        int readThisTime;
-        buffer = new byte[buffSize];
-        while (bytesRead < buffSize)
-        {
-            readThisTime = inStream.read(buffer, bytesRead, buffSize - bytesRead);
-            if (readThisTime == -1)
-            {
-                throw new IOException("Socket.receive(): Socket closed unexpectedly");
-            }
-            bytesRead += readThisTime;
-        }
-        return buffer;
-    }
 }
-
-//
-//        Channel channel = this.vdsCommClientService.getVdsClient().getChannel();
-//        if (channel == null || !channel.isActive()) {
-//            result.setResult(3, "VDS 서버와 통신이 실패하였습니다.");
-//            return result;
-//        }
-//        ChannelFuture f = channel.writeAndFlush(cmdBuffer);
-//        f.awaitUninterruptibly();
-//        if (f.isDone() || f.isSuccess()) {
-//            result.setResult(0, "VDS 서버에 요청 메시지를 정상적으로 전송하였습니다.");
-//        } else {
-//            result.setResult(4, "VDS 서버에 요청 메시지 전송이 실패하였습니다.");
-//        }

+ 256 - 0
src/main/java/com/its/op/service/its/xprotocol/CenterProtocol.java

@@ -0,0 +1,256 @@
+package com.its.op.service.its.xprotocol;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+public class CenterProtocol {
+
+    public static final ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
+    public static final int HEADER_SIZE = 10;
+
+    /*******************************************************************************
+     * 시스템 ID
+     *******************************************************************************/
+    public static final int INT_ID_TRAFFIC_SERVER		= 0x01;    /* 가공서버 */
+    public static final int INT_ID_SIGCTL_SERVER		= 0x02;    /* 신호제어서버 */
+    public static final int INT_ID_SIGCOM_SERVER		= 0x03;    /* 신호통신서버 */
+    public static final int INT_ID_VDS_SERVER			= 0x04;    /* VDS 서버 */
+    public static final int INT_ID_AVI_SERVER			= 0x05;    /* AVI 서버 */
+    public static final int INT_ID_DSRC_SERVER 			= 0x06;    /* DSRC 서버 */
+    public static final int INT_ID_VMS_SERVER 			= 0x07;    /* VMS 서버 */
+    public static final int INT_ID_CCTV_SERVER			= 0x08;    /* CCTV 서버 */
+    public static final int INT_ID_WEB_SERVER		   	= 0x09;    /* WEB 서버 */
+    public static final int INT_ID_UTIS_SERVER			= 0x0A;    /* UTIS 서버 */
+    public static final int INT_ID_KMA_SERVER			= 0x0B;    /* 기상청 연계 서버 */
+    public static final int INT_ID_WCAM_SERVER			= 0x0C;    /* 웹카메라 연계 서버 */
+    public static final int INT_ID_FCLT_SERVER			= 0x0D;    /* 시설물관리 서버 */
+    public static final int INT_ID_EXT01_SERVER			= 0x0E;    /* 연계 서버1 */
+    public static final int INT_ID_EXT02_SERVER			= 0x0F;    /* 연계 서버2 */
+    public static final int INT_ID_EXT03_SERVER			= 0x10;    /* 연계 서버3 */
+    public static final int INT_ID_CCAM_SERVER			= 0x11;    /* 교차로감시카메라 연계 서버 */
+    public static final int INT_ID_PARK_SERVER			= 0x12;    /* 주차장 연계 서버 */
+    public static final int INT_ID_RSE_SERVER			= 0x13;    /* RSE 연계 서버 */
+
+    public static final int INT_ID_MAIN_OPER 			= 0x21;    /* 통합운영단말 */
+    public static final int INT_ID_WALL_OPER 			= 0x22;    /* 상황판운영단말 */
+    public static final int INT_ID_SIG_OPER 			= 0x23;    /* 신호운영단말 */
+    public static final int INT_ID_VDS_OPER 			= 0x24;    /* VDS운영단말 */
+    public static final int INT_ID_AVI_OPER 			= 0x25;    /* AVI운영단말 */
+    public static final int INT_ID_DSRC_OPER 			= 0x26;    /* DSRC운영단말 */
+    public static final int INT_ID_VMS_OPER 			= 0x27;    /* VMS운영단말 */
+    public static final int INT_ID_CCTV_OPER 			= 0x28;    /* CCTV운영단말 */
+    public static final int INT_ID_FMS_OPER 			= 0x29;    /* 시설물관리단말 */
+    public static final int INT_ID_UTIS_OPER 			= 0x2A;    /* UTIS관리단말 */
+    public static final int INT_ID_WCAM_OPER 			= 0x2B;    /* WCAM관리단말 */
+
+    public static final int INT_ID_OPER_MIN 			= INT_ID_MAIN_OPER ;    /* 운영단말 최소값 */
+    public static final int INT_ID_OPER_MAX 			= INT_ID_WCAM_OPER ;    /* 운영단말 최대값 */
+
+    /*******************************************************************************
+     * 프로토콜 OP CODE 정의
+     *******************************************************************************/
+    public static final int INT_OP_TRAFFIC_CHANGE   	    = 0x10;        /* 교통정보가공완료 */
+    public static final int INT_OP_NODELINK_CHANGE          = 0x11;        /* 노드링크 기반 정보 변경 */
+    public static final int INT_OP_FACILITY_CHANGE          = 0x12;        /* 시설물 기반 정보 변경 */
+    public static final int INT_OP_PG_STATE_REQ             = 0x13;        /* 공통사항, 프로그램 동작상태 요청 */
+    public static final int INT_OP_PG_STATE_RES             = 0x14;        /* 공통사항, 프로그램 동작상태 응답 */
+    public static final int INT_OP_CHANGE_EVENT             = 0x15;        /* 공통사항, 마스터정보 변경 알림 */
+    public static final int INT_OP_INC_EVENT                = 0x16;        /* 공통사항, 돌발정보 전송 */
+    public static final int INT_OP_ACK                      = 0x17;        /* 공통사항, ACK(Acknowledge) */
+    public static final int INT_OP_NACK                     = 0x18;        /* 공통사항, NACK(Negative Acknowledge) */
+    public static final int INT_OP_EXTENSION                = 0x19;        /* 공통사항, EXTENSION 요청/응답 */
+
+    /*******************************************************************************
+     * VMS Protocol OP Code
+     *******************************************************************************/
+    public static final int INT_OP_VMS_STATE_REQ            = 0x21;        /* VMS 통신 서버, VMS 시설물 상태정보 요청 */
+    public static final int INT_OP_VMS_STATE_RES            = 0x22;        /* VMS 통신 서버, VMS 시설물 상태정보 전송 */
+    public static final int INT_OP_VMS_POWER_CTL            = 0x23;        /* VMS 통신 서버, VMS 전광판 On/Off 제어 */
+    public static final int INT_OP_VMS_LUMINANCE_CTL        = 0x24;        /* VMS 통신 서버, VMS 휘도 제어 */
+
+    public static final int INT_OP_VMS_PARA_SET             = 0x25;        /* VMS 통신 서버, VMS 환경설정정보 전송 */
+    public static final int INT_OP_VMS_PARA_SET2            = 0x26;        /* VMS 통신 서버, VMS 환경설정정보 전송(For Pasig) */
+    public static final int INT_OP_VMS_RESET                = 0x27;        /* VMS 통신 서버, VMS 제어기 리셋 전송 */
+    public static final int INT_OP_VMS_MODE                 = 0x28;        /* VMS 통신 서버, VMS 운영모드 변경 */
+    public static final int INT_OP_VMS_FORM_SAVE            = 0x29;        /* VMS 통신 서버, 실시간 VMS 제공정보 저장 */
+    public static final int INT_OP_VMS_FORM_DOWNLOAD        = 0x2A;        /* VMS 통신 서버, 실시간 VMS 제공정보 저장 */
+    public static final int INT_OP_VMS_IMAGE_SYMBOL         = 0x2B;        /* VMS image symbol update */
+    public static final int INT_OP_VMS_IMAGE_TRAFFIC        = 0x2C;        /* VMS image traffic update */
+    public static final int INT_OP_VMS_FORM_UPDATE          = 0x2D;        /* VMS form update */
+    public static final int INT_OP_VMS_IFSC_UPDATE          = 0x2E;        /* VMS ifsc update */
+
+    public static final int INT_OP_VMS_PARAM_RES            = 0x2F;        /* VMS 통신 서버, VMS 시설물 파라미터정보 전송 ==> 목포시 싸인텔레콤 추가 */
+
+    public static final int INT_OP_VMS_COMMON               = 0x30;        /* 신규로 생성될 명령어를 처리하기 위한 OP Code */
+    public static final int INT_OP_VMS_COMMON_EXT           = 0x31;        /* 신규로 생성될 명령어를 처리하기 위한 OP Code */
+    public static final int INT_OP_VMS_IMMEDIATE_SCN_DNLD   = 0x32;        /* 폼 즉시 다운로드 OP Code */
+    public static final int INT_OP_VMS_PARAM_REQ            = 0x33;        /* VMS 파라미터 요청 */
+    public static final int INT_OP_VMS_DIRECT               = 0x34;        /* VMS Direct command */
+
+
+    /*******************************************************************************
+     * VDS Protocol OP Code
+     *******************************************************************************/
+    public static final int INT_OP_VDS_STOP_IMAGE_REQ       = 0x50;        /* VDS 통신 서버, VDS 정지영상 요청 */
+    public static final int INT_OP_VDS_STOP_IMAGE_RES       = 0x51;        /* VDS 통신 서버, VDS 정지영상 요청 응답 */
+    public static final int INT_OP_VDS_STATE_RES            = 0x52;        /* VDS 통신 서버, VDS 시설물 상태정보 전송 */
+    public static final int INT_OP_VDS_FAN_CONTROL          = 0x54;        /* VDS 통신 서버, VDS FAN 제어 */
+    public static final int INT_OP_VDS_RESET                = 0x59;        /* VDS 통신 서버, VDS 제어기 리셋 전송 */
+
+    public static final int INT_OP_VDS_PARAM_REQ            = 0x55;        /* VDS 통신 서버, VDS 파라미터 요청 */
+    public static final int INT_OP_VDS_PARAM_RES            = 0x56;        /* VDS 통신 서버, VDS 파라미터 요청 응답 */
+    public static final int INT_OP_VDS_PARAM_SET_REQ        = 0x57;        /* VDS 통신 서버, VDS 파라미터 설정 요청 */
+    public static final int INT_OP_VDS_PARAM_SET_RES        = 0x58;        /* VDS 통신 서버, VDS 파라미터 설정 요청 응답 */
+
+    /*******************************************************************************
+     * DSRC Protocol OP Code
+     *******************************************************************************/
+    public static final int INT_OP_DSRC_CONTROL_REQ         = 0x60;        /* DSRC 통신 서버, DSRC 제어 요청 */
+    public static final int INT_OP_DSRC_CONTROL_RES         = 0x61;        /* DSRC 통신 서버, DSRC 제어 요청 응답 */
+    public static final int INT_OP_DSRC_STATE_RES           = 0x62;        /* DSRC 통신 서버, DSRC 시설물 상태정보 전송 */
+
+
+    /*******************************************************************************
+     * WCAM Protocol OP Code
+     *******************************************************************************/
+    public static final int INT_OP_WCAM_STATE_RES           = 0x70;        /* WCAM 통신 서버, WCAM 시설물 상태정보 전송 */
+
+    /*******************************************************************************
+     * CCAM Protocol OP Code
+     *******************************************************************************/
+    public static final int INT_OP_CCAM_STATE_RES           = 0x71;        /* CCAM 통신 서버, CCAM 시설물 상태정보 전송 */
+
+    /*******************************************************************************
+     * PARK Protocol OP Code
+     *******************************************************************************/
+    public static final int INT_OP_PARK_STATE_RES           = 0x81;        /* PARK 통신 서버, PARK 시설물 상태정보 전송 */
+
+    /*******************************************************************************
+     *  프로세스 상태정보 요청/응답
+     *******************************************************************************/
+    public static final int INT_MAX_PG_STATE                = 146;        /* 최대 프로그램 상태정보 */
+
+    /*******************************************************************************
+     *  돌발 발생 통보
+     *******************************************************************************/
+    public static final int INT_INC_TIME_SIZE           = 14;        /* 'YYYYMMDDHH24MISS' */
+    public static final int INT_INC_ID_SIZE             = 12;        /* 돌발 ID */
+
+    /*******************************************************************************
+     *  VMS
+     *******************************************************************************/
+    public static final int INT_VMS_MAX_ID              = 15;       /* VMS 제어기 ID */
+    public static final int INT_VMS_MAX_MODULE          = 100;      /* 최대 VMS 모듈 */
+    public static final int INT_VMS_MAX_POWER           = 10;       /* 최대 VMS 전원 */
+    public static final int INT_VMS_MAX_MODULE_BIT      = 100;      /* 최대 VMS 모듈 비트*/
+    public static final int INT_VMS_MAX_POWER_BIT       = 10;       /* 최대 VMS 전원 비트 */
+
+    public static final int INT_VMS_MAX_DATETIME        = 14;       /* YYYYMMDDHHMMSS */
+    public static final int INT_VMS_MAX_OPER_ID         = 20;
+
+    public static final int INT_VMS_MAX_STATE           = 80;       /* 최대 VMS 시설물 상태정보 */
+    public static final int INT_VMS_MAX_PARAM           = 100;      /* 최대 VMS 파라미터 */
+    public static final int INT_VMS_MAX_PREP            = 93;       /* 최대 VMS 폼 갯수 정보 */
+    public static final int INT_VMS_MAX_FORM            = 40;       /* 최대 VMS 폼 */
+    public static final int INT_VMS_MAX_OBJECT          = 64;       /* 최대 VMS 오브젝트 */
+    public static final int INT_VMS_MAX_STRING_BUF      = 64;       /* 최대 VMS 문자열 데이터 버퍼 */
+    public static final int INT_VMS_MAX_FORM_DOWNLOAD   = 100;      /* 최대 VMS 제공정보 저장 (256개 까지 증가 가능) */
+    public static final int INT_VMS_MAX_MODE            = 100;      /* 최대 VMS 모드변경 갯수 */
+
+    /*******************************************************************************
+     *  VDS
+     *******************************************************************************/
+    public static final int INT_VDS_MAX_DATETIME        = 14;       /* YYYYMMDDHHMMSS */
+    public static final int INT_VDS_MAX_OPER_ID         = 20;
+    public static final int INT_VDS_MAX_STATE           = 200;      /* 최대 VDS 시설물 상태정보 */
+    public static final int INT_VDS_MAX_STOP_IMAGE      = 65535;    /* 정지영상 패킷 최대크기 */
+    /* VDS 정지영상 요청 응답 */
+    public static final int ERR_VDS_STOP_IMAGE_NORMAL           = 0x00;
+    public static final int ERR_VDS_STOP_IMAGE_NOT_CONNECT      = 0x01;
+    public static final int ERR_VDS_STOP_IMAGE_BUSY             = 0x02;
+    public static final int ERR_VDS_STOP_IMAGE_UNKNOWN_ID       = 0x03;
+    public static final int ERR_VDS_STOP_IMAGE_SIZE             = 0x04;
+
+    /*******************************************************************************
+     *  DSRC
+     *******************************************************************************/
+    public static final int INT_DSRC_MAX_DATETIME        = 14;      /* YYYYMMDDHHMMSS */
+    public static final int INT_DSRC_MAX_OPER_ID         = 20;
+    public static final int INT_DSRC_MAX_STATE           = 200;     /* 최대 DSRC 시설물 상태정보 */
+
+    /**
+     * 센터 내부 통신 헤더 패킷 생성
+     * @param sndSystem
+     * @param rcvSystem
+     * @param opCode
+     * @param length
+     * @return
+     */
+    public static byte[] getRequestHead(int sndSystem, int rcvSystem, byte opCode, int length) {
+
+        ByteBuffer byteBuffer = ByteBuffer.allocate(10);
+        byteBuffer.order(ByteOrder.BIG_ENDIAN);
+        byteBuffer.put((byte)sndSystem); // 송신시스템-운영단말
+        byteBuffer.put((byte)rcvSystem); // 수신시스템
+        byteBuffer.put((byte)0x01); // 전체프레임개수
+        byteBuffer.put((byte)0x01); // 현재프레임번호
+        byteBuffer.put((byte)0x00); // Reserved
+        byteBuffer.put(opCode);     // OP Code
+        byteBuffer.putInt(length);  // 데이터 길이
+
+        //log.error("HEAD: {}", SysUtils.byteArrayToHex(byteBuffer.array()));
+        return byteBuffer.array();
+    }
+
+    /**
+     * 통신 서버와 통신 연결
+     * @param ipAddress
+     * @param port
+     * @param connTimeout
+     * @param readTimeout
+     * @return
+     * @throws IOException
+     */
+    public static Socket connectServer(String ipAddress, int port, int connTimeout, int readTimeout) throws IOException {
+        SocketAddress socketAddress = new InetSocketAddress(ipAddress, port);
+        Socket socket = null;
+        try {
+            socket = new Socket();
+            socket.setSoTimeout(readTimeout);                /* InputStream 에서 데이터읽을때의 timeout */
+            socket.connect(socketAddress, connTimeout);  /* socket 연결 자체에대한 timeout */
+        } catch (IOException e) {
+            throw e;
+        }
+        return socket;
+    }
+
+    /**
+     * 소켓 입력 버퍼로 부터 데이터 길이만큼 읽어 온다
+     * @param inStream
+     * @param buffSize
+     * @return
+     * @throws IOException
+     */
+    public static byte[] receiveBytes(InputStream inStream, int buffSize) throws IOException {
+        byte[] buffer;
+        int bytesRead = 0;
+        int readThisTime;
+        buffer = new byte[buffSize];
+        while (bytesRead < buffSize)
+        {
+            readThisTime = inStream.read(buffer, bytesRead, buffSize - bytesRead);
+            if (readThisTime == -1)
+            {
+                throw new IOException("Socket.receive(): Socket closed unexpectedly");
+            }
+            bytesRead += readThisTime;
+        }
+        return buffer;
+    }
+
+}