XFrameBrowser MainScreen 가이드

이 화면은 XPlusTcpSvr.ocx 컴포넌트에 대한 샘플 화면이다.

XPlusTcpSvr.ocx 컴포넌트는 TCP 서버 소켓 기능을 제공하는 컴포넌트이다.

템플릿 위치: /XPLUS/xplus_tcpsvr

템플릿 파일

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
 * XPlusTcpSvr 데이터 수신 이벤트 처리
 * @param objInst XPlusTcpSvr 오브젝트
 * @param pRemoteIpAddr 데이터를 송신한 시스템의 IP 주소
 * @param nRemotePortNo 데이터를 송신한 시스템의 TCP 포트 번호
 * @param nSocketKey 소켓 키 값
 * @param nLength 수신한 데이터 길이
 * @param pDataKey 수신한 데이터에 대한 Key값, GetData 함수에서 사용됨
 */
function objXPlusTcpSvr_OnReceive(objInst,pRemoteIpAddr,nRemotePortNo,nSocketKey,nLength,pDataKey)
{
    factory.consoleprint("pRemoteIpAddr = " + pRemoteIpAddr);
    factory.consoleprint("nRemotePortNo = " + nRemotePortNo);
    factory.consoleprint("nSocketKey = " + nSocketKey);
    factory.consoleprint("nLength = " + nLength);
    factory.consoleprint("pDataKey = " + pDataKey);
 
    fldRecvIpAddr.settext(pRemoteIpAddr);
    fldRecvPortNo.settext(nRemotePortNo);
    fldRecvDataLength.settext(nLength);
 
    /**
     * 실제 수신된 데이터를 구함
     * @return strRecvData 수신한 데이터
     */
    var strRecvData = objXPlusTcpSvr.innerctrl.GetData(pDataKey);
    factory.consoleprint("RecvData = " + strRecvData);
    fldRecvData.settext(strRecvData);
 
    return;
}
 
/**
 * TCP 세션이 연결되면 발생하는 이벤트 처리
 * @param objInst XPlusTcpSvr 오브젝트
 * @param pRemoteIpAddr 원격지 시스템의 IP 주소
 * @param nRemotePortNo 원격지 시스템의 TCP 포트 번호
 * @param nSocketKey 소켓 키 값
 */
function objXPlusTcpSvr_OnConnect(objInst,pRemoteIpAddr,nRemotePortNo,nSocketKey)
{
    factory.consoleprint("SessionConnected> pRemoteIpAddr = " + pRemoteIpAddr);
    factory.consoleprint("SessionConnected> nRemotePortNo = " + nRemotePortNo);
    factory.consoleprint("SessionConnected> nSocketKey = " + nSocketKey);
 
    var nRow = grdSessionList.additem();
    grdSessionList.setitemtext(nRow, 0, pRemoteIpAddr);
    grdSessionList.setitemtext(nRow, 1, nRemotePortNo);
}
 
/**
 * TCP 세션이 해제되면 발생하는 이벤트 처리
 * @param objInst XPlusTcpSvr 오브젝트
 * @param pRemoteIpAddr 세션이 해제된 시스템의 IP 주소
 * @param nRemotePortNo 세션이 해제된 시스템의 TCP 포트 번호
 * @param nSocketKey 소켓 키 값
 */
function objXPlusTcpSvr_OnClose(objInst,pRemoteIpAddr,nRemotePortNo,nSocketKey)
{
    factory.consoleprint("SessionClosed> pRemoteIpAddr = " + pRemoteIpAddr);
    factory.consoleprint("SessionClosed> nRemotePortNo = " + nRemotePortNo);
    factory.consoleprint("SessionClosed> nSocketKey = " + nSocketKey);
 
    var nRowCount = grdSessionList.getrowcount();
    var i;
 
    for(i = 0; i < nRowCount; i++) {
        if(grdSessionList.getitemtext(i, 0) == pRemoteIpAddr) {
            if(grdSessionList.getitemtext(i, 1) == nRemotePortNo) {
                grdSessionList.deleterow(i);
                break;
            }
        }
    }
 
    return;
}
 
// XTcpSvrComm 초기화
function btnInitXTcpSvrComm_on_mouseup(objInst)
{
    var strBindPortNo = fldBindPortNo.gettext();
    var strLogDir = "C:\\xFrame\\log";
    var nRet;
 
    /**
     * XPlusTcpSvr 초기화, 처음 시작시 한번만 호출해야 함
     * @param pLogDir 로그 저장 디렉토리 경로
     * @param pLogFilePrefix 로그 파일 이름
     * @param pLogLevel 로그 레벨 ("DEBUG", "INFO", "WARN", "ERROR", "FATAL") ("DEBUG" 레벨 지정시 송수신 데이터 로깅)
     * @param nLogEncFlag 로그 암호화 여부 플래그 (0 또는 1)
     * @param nBindPortNo Listen할 TCP 포트 번호
     * @param nLengthFieldLength 데이터 길이 필드 길이
     * @param nLenIncFlag 길이 필드 계산시 길이 필드 자체 포함 여부 (0 또는 1)
     * @returns 처리 결과 값
     *  0: Success
     *   1: Already Initialized
     *   2: Invalid Port Number
     *   3: Invlalid Length Field Length
     */
    nRet = objXPlusTcpSvr.innerctrl.InitXPlusTcpSvr(strLogDir, "XPlusTcpSvr", "DEBUG", 0, strBindPortNo, 8, 0);
    factory.consoleprint("InitXPlusTcpSvr Return Value = " + nRet);
    if(nRet != 0) {
        screen.alert("InitXPlusTcpSvr() Fail, ErrorCode = " + nRet);
    }
 
    /**
     * TCP 송수신 데이터에 대한 UTF8 문자셋 처리 설정
     * @param nSocketKey 소켓 키 값
     * @returns 연결 여부 값
     *      0: Success
     *      1: Invalid Parameter
     */
    nRet = objXPlusTcpSvr.innerctrl.SetUtf8Flag(1);
    factory.consoleprint("SetUtf8Flag Return Value = " + nRet);
 
    /**
     * TCP 데이터 송신 타임아웃(단위: 밀리초) 설정
     * @param nSocketKey 소켓 키 값
     * @returns 연결 여부 값
     *      0: Success
     *      1: Invalid Parameter
     */
    nRet = objXPlusTcpSvr.innerctrl.SetSendTimeout(5000);   // 5초
    factory.consoleprint("SetSendTimeout Return Value = " + nRet);
}
 
// XTcpSvrComm 시작 버튼 클릭 이벤트 처리
function btnStartXTcpSvrComm_on_mouseup(objInst)
{
    /**
     * XPlusTcpSvr 소켓을 열고 TCP 접속 대기
    * @param nBindPortNo Listen할 TCP 포트 번호 (0 값을 지정할 경우, InitXPlusTcpSvr 함수에서 지정한 포트 사용)
     * @returns 처리 결과 값
     *  0: Success
     *   1: Invalid Port No
     *   2: Fail To Create Socket
     *   3: Fail To Socket Listen
     *   9: Not Initialized
     */
    nRet = objXPlusTcpSvr.innerctrl.StartXPlusTcpSvr(0);
    factory.consoleprint("StartXPlusTcpSvr Return Value = " + nRet);
    if(nRet != 0) {
        screen.alert("StartXPlusTcpSvr() Fail, ErrorCode = " + nRet);
    }
}
 
// XTcpSvrComm 종료 버튼 클릭 이벤트 처리
function btnStopXTcpSvrComm_on_mouseup(objInst)
{
    /**
     * XPlusTcpSvr 소켓을 닫고, 연결된 TCP 접속 해제
     * @param nCloseSessionFlag 연결되어 있는 TCP 세션 해제 여부
     * @param nFireEventFlag 세션 해제 이벤트 발생 처리 여부 플래그
     * @returns 처리 결과 값
     *      0: Success
     *      9: Not Initialized
     */
    var nCloseSessionFlag = 1;
    var nFireEventFlag = 0;
    var nRet;
 
    nRet = objXPlusTcpSvr.innerctrl.StopXPlusTcpSvr(nCloseSessionFlag, nFireEventFlag);
    factory.consoleprint("StopXPlusTcpSvr Return Value = " + nRet);
    if(nRet != 0) {
        screen.alert("StopXPlusTcpSvr() Fail, ErrorCode = " + nRet);
    }
 
    grdSessionList.deleteall();
}
// 세션 해제 버튼 클릭 이벤트 처리
function btnCloseSession_on_mouseup(objInst)
{
    var nCheckedRowCount = grdSessionList.getcheckedrowcount();
    if(nCheckedRowCount == 0) {
        screen.alert("연결 해제할 세션을 체크하세요.");
        return;
    }
 
    var nCheckedRow = grdSessionList.getcheckedrow(0);
    var strRemoteIpAddr = grdSessionList.getitemtext(nCheckedRow, 0);
    var strRemotePortNo = grdSessionList.getitemtext(nCheckedRow, 1);
    var nRet;
 
    /**
     * 지정된 TCP 세션을 해재한다.
     * @param strRemoteIpAddr 데이터 수신 대상 시스템 IP 주소
     * @param strRemotePortNo 데이터 수신 대상 포트 번호
     * @param nFireEventFlag 세션 해제 이벤트 발생 처리 여부 플래그
     * @return
     *  0 : OK
     *  1 : Invalid Parameter
     *  2 : Fail To Find Session
     *  9 : Not Initialized
     */
    var nFireEventFlag = 1;
    nRet = objXPlusTcpSvr.innerctrl.CloseSession(strRemoteIpAddr, strRemotePortNo, nFireEventFlag);
    // nRet = objXPlusTcpSvr.innerctrl.CloseSessionByKey(nSocketKey, nFireEventFlag);
    factory.consoleprint("CloseSession Return Value = " + nRet);
    if(nRet != 0) {
        screen.alert("CloseSession() Fail, ErrorCode = " + nRet);
    }
}
 
// 데이터 송신 버튼 클릭 이벤트 처리
function btnSendData_on_mouseup(objInst)
{
    var nCheckedRowCount = grdSessionList.getcheckedrowcount();
    if(nCheckedRowCount == 0) {
        screen.alert("데이터를 송신할 세션을 체크하세요.");
        return;
    }
 
    var nCheckedRow = grdSessionList.getcheckedrow(0);
    var strRemoteIpAddr = grdSessionList.getitemtext(nCheckedRow, 0);
    var nRemotePortNo = grdSessionList.getitemtext(nCheckedRow, 1);
    var strSendData = fldSendData.gettext();
    var nRet;
 
    /**
     * 데이터 송신
     * @param pRemoteIpAddr 데이터를 송신할 대상 시스템 IP 주소
     * @param nRemotePortNo 데이터를 송신할 대상 시스템 포트 번호
     * @param pData 송신할 데이터
     * @returns 처리 결과 값
     *      0: OK
     *      1: Fail To Find Session
     *      2: Invalid Parameter
     *      3: Session is Not Connected
     *      4: Fail To Send Length Part
     *      5: Fail To Send Data Part
     *      9: Not Initialized
     */
    nRet = objXPlusTcpSvr.innerctrl.SendData(strRemoteIpAddr, nRemotePortNo, strSendData);
    // nRet = objXPlusTcpSvr.innerctrl.SendDataByKey(nSocketKey, strSendData);
    factory.consoleprint("SendData Return Value = " + nRet);
    if(nRet != 0) {
        screen.alert("SendData() Fail, ErrorCode = " + nRet);
    }
}
 
// 수신 데이터 정보 초기화 버튼 클릭 이벤트 처리
function btnClearData_on_mouseup(objInst)
{
    fldRecvIpAddr.settext("");
    fldRecvPortNo.settext("");
    fldRecvDataLength.settext("");
    fldRecvData.settext("");
}

  • guide/xplus/xplus_tcpsvr.txt
  • 마지막으로 수정됨: 2023/05/11 16:21
  • 저자 127.0.0.1