UDPCOMM 가이드

이 화면은 UDP통신 컴포넌트에 대한 샘플 화면이다.

UDP통신 컴포넌트는 UDP 서버/클라이언트 소켓 기능을 제공하는 컴포넌트이다.

템플릿 위치: /HTML5/COMPONENT/UDPCOMM/udpcomm_basic

템플릿 파일

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
function screen_on_load()
{
    fldSendData1.settext("1234ABCD가나다라1");
    fldSendData2.settext("1234ABCD가나다라2");
}
 
function btnInitXPlusUdpSvrComm_on_mouseup(objInst)
{
    // 초기화
    udpsvr01.init();
}
 
function btnInitXPlusUdpCltComm_on_mouseup(objInst)
{
    // 초기화
    udpclt01.init();
}
 
function btnOpenUdpSvrSocket_on_mouseup(objInst)
{
    // 시작
    udpsvr01.open(fldUdpSvrPortNo.gettext());
}
 
function btnOpenUdpCltSocket_on_mouseup(objInst)
{
    // 시작
    udpclt01.open(fldUdpCltPortNo.gettext());
}
 
function btnCloseUdpSvrSocket_on_mouseup(objInst)
{
    // 종료
    udpsvr01.close();
}
 
function btnCloseUdpCltSocket_on_mouseup(objInst)
{
    // 종료
    udpclt01.close();
}
 
function btnSendData1_on_mouseup(objInst)
{
    // 데이터 송신
    udpsvr01.send(fldReceiverIpAddr1.gettext(), fldReceiverPortNo1.gettext(), fldSendData1.gettext());
}
 
function btnSendData2_on_mouseup(objInst)
{
    // 데이터 송신
    udpclt01.send(fldReceiverIpAddr2.gettext(), fldReceiverPortNo2.gettext(), fldSendData2.gettext());
}
 
function btnClearData1_on_mouseup(objInst)
{
    // 수신 데이터 정보 초기화
    fldRecvDataLength1.settext("");
    fldSenderIpAddr1.settext("");
    fldSenderPortNo1.settext("");
    fldRecvData1.settext("");
}
 
function btnClearData2_on_mouseup(objInst)
{
    // 수신 데이터 정보 초기화
    fldRecvDataLength2.settext("");
    fldSenderIpAddr2.settext("");
    fldSenderPortNo2.settext("");
    fldRecvData2.settext("");
}
 
/////////////////////////////////////////////////////////////////////////////////////////
// EVENT
/////////////////////////////////////////////////////////////////////////////////////////
 
/**
 * 모듈 로딩 완료 및 컴포넌트 초기화 성공시 이벤트
 * @param objInst UDP통신 컴포넌트 오브젝트
 */
function udpsvr01_on_init(objInst)
{
    factory.consoleprint(objInst.getname() + "_on_init>");
    console.log(objInst.getname() + "_on_init>");
}
 
/**
 * UDP 세션 연결시 이벤트
 * @param objInst UDP통신 컴포넌트 오브젝트
 * @param nLocalPort 연결된 세션의 로컬포트
 */
function udpsvr01_on_open(objInst, nLocalPort)
{
    factory.consoleprint(objInst.getname() + "_on_open : " + nLocalPort);
    console.log(objInst.getname() + "_on_open : " + nLocalPort);
}
 
/**
 * 데이터 수신 이벤트 처리
 * @param objInst UDP통신 컴포넌트 오브젝트
 * @param nDataLen 수신한 데이터 길이
 * @param strData 수신한 데이터
 * @param strRemoteIP 데이터를 송신한 IP 주소
 * @param nRemotePort 데이터를 송신한 UDP 포트 번호
 */
function udpsvr01_on_recv(objInst, nDataLen, strData, strRemoteIP, nRemotePort)
{
    factory.consoleprint("nDataLen = " + nDataLen);
    factory.consoleprint("strData = " + strData);
 
    fldRecvDataLength1.settext(nDataLen);
    fldSenderIpAddr1.settext(strRemoteIP);
    fldSenderPortNo1.settext(nRemotePort);
    fldRecvData1.settext(strData);
}
 
/**
 * 에러 발생시 이벤트
 * @param objInst UDP통신 컴포넌트 오브젝트
 * @param nErrorCode 에러코드
 * @param strErrorMsg 에러메시지
 * @param strRemoteIP 데이터를 송신한 IP 주소(수신에 실패한 경우는 빈값)
 * @param nRemotePort 데이터를 송신한 UDP 포트 번호(수신에 실패한 경우는 0)
 */
function udpsvr01_on_error(objInst, nErrorCode, strErrorMsg, strRemoteIP, nRemotePort)
{
    if (strRemoteIP == "") {
        screen.alert(objInst.getname() + "_on_error : " + nErrorCode + ", " + strErrorMsg);
    } else {
        screen.alert(objInst.getname() + "_on_error : " + nErrorCode + ", " + strErrorMsg + ", " + strRemoteIP + ", " + nRemotePort);
    }
}
 
/**
 * 모듈 로딩 완료 및 컴포넌트 초기화 성공시 이벤트
 * @param objInst UDP통신 컴포넌트 오브젝트
 */
function udpclt01_on_init(objInst)
{
    factory.consoleprint(objInst.getname() + "_on_init>");
    console.log(objInst.getname() + "_on_init>");
}
 
/**
 * UDP 세션 연결시 이벤트
 * @param objInst UDP통신 컴포넌트 오브젝트
 * @param nLocalPort 연결된 세션의 로컬포트
 */
function udpclt01_on_open(objInst, nLocalPort)
{
    factory.consoleprint(objInst.getname() + "_on_open : " + nLocalPort);
    console.log(objInst.getname() + "_on_open : " + nLocalPort);
 
    fldUdpCltPortNo.settext(nLocalPort);
    fldReceiverPortNo1.settext(nLocalPort);
}
 
/**
 * 데이터 수신 이벤트 처리
 * @param objInst UDP통신 컴포넌트 오브젝트
 * @param nDataLen 수신한 데이터 길이
 * @param strData 수신한 데이터
 * @param strRemoteIP 데이터를 송신한 IP 주소
 * @param nRemotePort 데이터를 송신한 UDP 포트 번호
 */
function udpclt01_on_recv(objInst, nDataLen, strData, strRemoteIP, nRemotePort)
{
    factory.consoleprint("nDataLen = " + nDataLen);
    factory.consoleprint("strData = " + strData);
 
    fldRecvDataLength2.settext(nDataLen);
    fldSenderIpAddr2.settext(strRemoteIP);
    fldSenderPortNo2.settext(nRemotePort);
    fldRecvData2.settext(strData);
}
 
/**
 * 에러 발생시 이벤트
 * @param objInst UDP통신 컴포넌트 오브젝트
 * @param nErrorCode 에러코드
 * @param strErrorMsg 에러메시지
 * @param strRemoteIP 데이터를 송신한 IP 주소(수신에 실패한 경우는 빈값)
 * @param nRemotePort 데이터를 송신한 UDP 포트 번호(수신에 실패한 경우는 0)
 */
function udpclt01_on_error(objInst, nErrorCode, strErrorMsg, strRemoteIP, nRemotePort)
{
    if (strRemoteIP != "") {
        // 데이터 송신 실패
        screen.alert(objInst.getname() + "_on_error : " + nErrorCode + ", " + strErrorMsg + ", " + strRemoteIP + ", " + nRemotePort);
    } else {
        // 그 외의 오류 (데이터 수신 실패, API 처리 실패)
        screen.alert(objInst.getname() + "_on_error : " + nErrorCode + ", " + strErrorMsg);
    }
}

  • guide/component/udpcomm/udpcomm_basic.txt
  • 마지막으로 수정됨: 2023/11/08 10:13
  • 저자 127.0.0.1