@@ -21,6 +21,9 @@ public class EzyTcpClient :
21
21
protected EzyUser me ;
22
22
protected EzyZone zone ;
23
23
protected long sessionId ;
24
+ protected byte [ ] publicKey ;
25
+ protected byte [ ] privateKey ;
26
+ protected byte [ ] sessionKey ;
24
27
protected String sessionToken ;
25
28
protected readonly String name ;
26
29
protected readonly EzySetup settingUp ;
@@ -127,8 +130,10 @@ public bool reconnect()
127
130
}
128
131
preconnect ( ) ;
129
132
bool success = socketClient . reconnect ( ) ;
130
- if ( success )
131
- setStatus ( EzyConnectionStatus . RECONNECTING ) ;
133
+ if ( success )
134
+ {
135
+ setStatus ( EzyConnectionStatus . RECONNECTING ) ;
136
+ }
132
137
return success ;
133
138
}
134
139
@@ -143,24 +148,46 @@ public void disconnect(int reason)
143
148
socketClient . disconnect ( reason ) ;
144
149
}
145
150
146
- public void send ( EzyRequest request )
151
+ public void close ( )
152
+ {
153
+ disconnect ( ( int ) EzyDisconnectReason . CLOSE ) ;
154
+ }
155
+
156
+ public void send ( EzyRequest request , bool encrypted )
147
157
{
148
158
Object cmd = request . getCommand ( ) ;
149
159
EzyData data = request . serialize ( ) ;
150
- send ( ( EzyCommand ) cmd , ( EzyArray ) data ) ;
160
+ send ( ( EzyCommand ) cmd , ( EzyArray ) data , encrypted ) ;
151
161
}
152
162
153
- public void send ( EzyCommand cmd , EzyArray data )
154
- {
163
+ public void send ( EzyCommand cmd , EzyArray data , bool encrypted )
164
+ {
165
+ bool shouldEncrypted = encrypted ;
166
+ if ( encrypted && sessionKey == null )
167
+ {
168
+ if ( config . isEnableDebug ( ) )
169
+ {
170
+ shouldEncrypted = false ;
171
+ }
172
+ else
173
+ {
174
+ throw new ArgumentException (
175
+ "can not send command: " + cmd + " " +
176
+ "you must enable SSL or enable debug mode by configuration " +
177
+ "when you create the client"
178
+ ) ;
179
+ }
180
+
181
+ }
155
182
EzyArray array = requestSerializer . serialize ( cmd , data ) ;
156
- if ( socketClient != null )
183
+ if ( socketClient != null )
157
184
{
158
- socketClient . sendMessage ( array ) ;
185
+ socketClient . sendMessage ( array , shouldEncrypted ) ;
159
186
printSentData ( cmd , data ) ;
160
187
}
161
- }
188
+ }
162
189
163
- public void processEvents ( )
190
+ public void processEvents ( )
164
191
{
165
192
socketClient . processEventMessages ( ) ;
166
193
}
@@ -175,7 +202,17 @@ public EzyClientConfig getConfig()
175
202
return config ;
176
203
}
177
204
178
- public EzyZone getZone ( )
205
+ public bool isEnableSSL ( )
206
+ {
207
+ return config . isEnableSSL ( ) ;
208
+ }
209
+
210
+ public bool isEnableDebug ( )
211
+ {
212
+ return config . isEnableDebug ( ) ;
213
+ }
214
+
215
+ public EzyZone getZone ( )
179
216
{
180
217
return zone ;
181
218
}
@@ -237,6 +274,38 @@ public void setSessionToken(String token)
237
274
this . socketClient . setSessionToken ( sessionToken ) ;
238
275
}
239
276
277
+ public void setSessionKey ( byte [ ] sessionKey )
278
+ {
279
+ this . sessionKey = sessionKey ;
280
+ this . socketClient . setSessionKey ( sessionKey ) ;
281
+ }
282
+
283
+ public byte [ ] getSessionKey ( )
284
+ {
285
+ return sessionKey ;
286
+ }
287
+
288
+ public void setPublicKey ( byte [ ] publicKey )
289
+ {
290
+ this . publicKey = publicKey ;
291
+ }
292
+
293
+ public byte [ ] getPublicKey ( )
294
+ {
295
+ return publicKey ;
296
+ }
297
+
298
+ public void setPrivateKey ( byte [ ] privateKey )
299
+ {
300
+ this . privateKey = privateKey ;
301
+ }
302
+
303
+ public byte [ ] getPrivateKey ( )
304
+ {
305
+ return privateKey ;
306
+ }
307
+
308
+
240
309
public EzyISocketClient getSocket ( )
241
310
{
242
311
return socketClient ;
@@ -303,7 +372,9 @@ public EzyHandlerManager getHandlerManager()
303
372
protected void printSentData ( EzyCommand cmd , EzyArray data )
304
373
{
305
374
if ( ! unloggableCommands . Contains ( cmd ) )
375
+ {
306
376
logger . debug ( "send command: " + cmd + " and data: " + data ) ;
377
+ }
307
378
}
308
379
309
380
public virtual void udpConnect ( int port )
@@ -316,12 +387,12 @@ public virtual void udpConnect(String host, int port)
316
387
throw new InvalidOperationException ( "only support TCP, use EzyUTClient instead" ) ;
317
388
}
318
389
319
- public virtual void udpSend ( EzyRequest request )
390
+ public virtual void udpSend ( EzyRequest request , bool encrypted )
320
391
{
321
392
throw new InvalidOperationException ( "only support TCP, use EzyUTClient instead" ) ;
322
393
}
323
394
324
- public virtual void udpSend ( EzyCommand cmd , EzyArray data )
395
+ public virtual void udpSend ( EzyCommand cmd , EzyArray data , bool encrypted )
325
396
{
326
397
throw new InvalidOperationException ( "only support TCP, use EzyUTClient instead" ) ;
327
398
}
0 commit comments